MCPcopy Create free account
hub / github.com/WinVector/Logistic / expScaleFast

Method expScaleFast

src/com/winvector/opt/impl/HelperFns.java:134–159  ·  view source on GitHub ↗

can use- but approximation adds noise in gradient and such @param r

(final double[] r)

Source from the content-addressed store, hash-verified

132 * @param r
133 */
134 public static void expScaleFast(final double[] r) {
135 final int n = r.length;
136 if(n>0) {
137 double max = r[0];
138 for(int i=1;i<n;++i) {
139 max = Math.max(max,r[i]);
140 }
141 double total = 0.0;
142 for(int i=0;i<n;++i) {
143 final double diff = r[i] - max;
144 final double vi;
145 if(diff<0.0) {
146 vi = HelperFns.exp(diff);
147
148 } else {
149 vi = estExp0;
150 }
151 r[i] = vi;
152 total += vi;
153 }
154 final double scale = 1.0/total;
155 for(int i=0;i<n;++i) {
156 r[i] *= scale;
157 }
158 }
159 }
160
161 public static void main(String[] args) {
162 final double x = -0.3;

Callers 1

predictMethod · 0.95

Calls 1

expMethod · 0.95

Tested by

no test coverage detected