File: thresh.hoc

package info (click to toggle)
neuron 7.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 48,268 kB
  • sloc: cpp: 192,952; ansic: 145,860; python: 42,092; sh: 10,507; makefile: 6,816; yacc: 3,259; java: 995; lex: 457; csh: 108; pascal: 37; sed: 5
file content (46 lines) | stat: -rwxr-xr-x 1,102 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Determine strength of argument to within epsilon, that excites cell.

// This function requires an existing APCount[0] at the user desired location
// returns 1 if the voltage passed the APCount[0].thresh
func thresh_excited() {
	run()
	return APCount[0].n > 0
}

// do a binary search for threshold
func threshold() { local low, high, epsilon
	// the "call by reference" arg $&1 is the independent variable

	// bounding the threshold first can save several iterations
	low = 0 	high = 1e5
	if ($&1 == 0) { $&1 = 1 }
	while (low == 0 || high == 1e5) {
		if (thresh_excited()) {
			high = $&1
			$&1 = high/2
		} else {
			low = $&1
			$&1 = 2*low
		}
		if (stoprun) return $&1
		if (low > high) return high
	}

	// at this point high is not more than twice the theshold and
	// low is not less than half the threshold

	epsilon = 1e-7 + 1e-3 * high	// three decimal places accuracy
	/* now narrow the bounds */
	$&1 = (high + low)/2
	while ( (high - low) > epsilon) {
		if (thresh_excited()) {
			high = $&1
		} else {
			low = $&1
		}
		$&1 = (high + low)/2
		if (stoprun) break
	}
	return $&1
}