本文整理匯總了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())
}