本文整理汇总了TypeScript中core/util/array.argmin函数的典型用法代码示例。如果您正苦于以下问题:TypeScript argmin函数的具体用法?TypeScript argmin怎么用?TypeScript argmin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了argmin函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: get_best_ticker
get_best_ticker(data_low: number, data_high: number, desired_n_ticks: number) {
const data_range = data_high - data_low
const ideal_interval = this.get_ideal_interval(data_low, data_high, desired_n_ticks)
const ticker_ndxs = [
sortedIndex(this.min_intervals, ideal_interval) - 1,
sortedIndex(this.max_intervals, ideal_interval),
]
const intervals = [
this.min_intervals[ticker_ndxs[0]],
this.max_intervals[ticker_ndxs[1]],
]
const errors = intervals.map((interval) => {
return Math.abs(desired_n_ticks - (data_range / interval))
})
let best_ticker
if (isEmpty(errors.filter((e) => !isNaN(e)))) {
// this can happen if the data isn't loaded yet, we just default to the first scale
best_ticker = this.tickers[0]
} else {
const best_index = argmin(errors)
const best_ticker_ndx = ticker_ndxs[best_index]
best_ticker = this.tickers[best_ticker_ndx]
}
return best_ticker
}
示例2: get_interval
get_interval(data_low: number, data_high: number, desired_n_ticks: number) {
const data_range = data_high - data_low
const ideal_interval = this.get_ideal_interval(data_low, data_high, desired_n_ticks)
const interval_exponent = Math.floor(log(ideal_interval / this.base_factor, this.base))
const ideal_magnitude = Math.pow(this.base, interval_exponent) * this.base_factor
// An untested optimization.
// const ideal_mantissa = ideal_interval / ideal_magnitude
// index = sortedIndex(this.extended_mantissas, ideal_mantissa)
// candidate_mantissas = this.extended_mantissas[index..index + 1]
const candidate_mantissas = this.extended_mantissas
const errors = candidate_mantissas.map((mantissa) => {
return Math.abs(desired_n_ticks - (data_range / (mantissa * ideal_magnitude)))
})
const best_mantissa = candidate_mantissas[argmin(errors)]
const interval = best_mantissa*ideal_magnitude
return clamp(interval, this.get_min_interval(), this.get_max_interval())
}