Skip to content

Commit

Permalink
feat: reiterate that default ci_length is 0.9 so cache is used.
Browse files Browse the repository at this point in the history
  • Loading branch information
NunoSempere committed Mar 22, 2023
1 parent 170fbf2 commit 1b70a9a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/example.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {find_beta_from_ci} from "./index.js"

console.log({ci_lower: 0.3, ci_upper: 0.8})
let result1 = find_beta_from_ci({ci_lower: 0.3, ci_upper: 0.8})
console.log(result1)

/*
let result2 = find_beta_from_ci({ci_lower: 0.3, ci_upper: 0.8, ci_length: 0.95})
console.log(result2)
let result3 = find_beta_from_ci({ci_lower: 0.001, ci_upper: 0.01, ci_length: 0.90})
console.log(result3)

*/
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const find_beta_from_ci_nelder_mead = ({ci_lower, ci_upper, ci_length}) =
}

export const find_beta_from_ci_cache = ({ci_lower, ci_upper, ci_length}) => {
ci_length = (ci_length > 0 && ci_length < 1) ? (ci_length || 0.9) : 0.9
if(ci_length == 0.9 && !!cache[ci_lower] && !!cache[ci_lower][ci_upper]){
return cache[ci_lower][ci_upper]
} else {
Expand All @@ -114,10 +115,13 @@ export const find_beta_from_ci_cache = ({ci_lower, ci_upper, ci_length}) => {
}

export const find_beta_from_ci = ({ci_lower, ci_upper, ci_length}) => {
ci_length = (ci_length > 0 && ci_length < 1) ? (ci_length || 0.9) : 0.9
let cache_answer = find_beta_from_ci_cache({ci_lower, ci_upper, ci_length})
if(cache_answer != null ){
// console.log("Answer in the cache")
return cache_answer
} else {
// console.log("Answer from Nelder Mead")
let nelder_mead_answer = find_beta_from_ci_nelder_mead({ci_lower, ci_upper, ci_length})
return nelder_mead_answer
}
Expand Down

0 comments on commit 1b70a9a

Please sign in to comment.