MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / transform

Method transform

JSAT/src/jsat/classifiers/neuralnetwork/RBFNet.java:224–271  ·  view source on GitHub ↗
(DataPoint dp)

Source from the content-addressed store, hash-verified

222 }
223
224 @Override
225 public DataPoint transform(DataPoint dp)
226 {
227 final Vec x = dp.getNumericalValues();
228 final List<Double> qi = dm.getQueryInfo(x);
229 Vec sv = new SparseVector(numCentroids);
230 double sum = 0;
231 /*
232 * Keep track of the highest activation in case none of the neurons have
233 * a numericaly stable activation value. if this occurs we will do our
234 * best by simply setting the one largest activation
235 */
236 double maxActivation = Double.NEGATIVE_INFINITY;
237 int highestNeuron = -1;
238
239 for(int i = 0; i < centroids.size(); i++)
240 {
241 double dist = dm.dist(i, x, qi, centroids, centroidDistCache);
242 double sig = bandwidths[i];
243 double activation = Math.exp(-(dist*dist)/(sig*sig*2));
244
245 if(activation > maxActivation)
246 {
247 maxActivation = activation;
248 highestNeuron = i;
249 }
250
251 if(activation > 1e-16)
252 {
253 sv.set(i, activation);
254 sum += activation;
255 }
256 }
257
258 if(sv.nnz() == 0)//no activations
259 {
260 sv.set(highestNeuron, maxActivation);
261 sum = maxActivation;
262 }
263
264
265 if(normalize && sum != 0.0)//-0.0 not an issue with rbf kernel
266 sv.mutableDivide(sum);
267 if(sv.nnz() > sv.length()/2)//at this point we would be using more memory than needed. Just switch to dense
268 sv = new DenseVector(sv);
269
270 return new DataPoint(sv, dp.getCategoricalValues(), dp.getCategoricalData(), dp.getWeight());
271 }
272 /**
273 * The first phase of learning a RBF Neural Network is to determine the
274 * neuron locations. This enum controls which method is used.

Callers 2

classifyMethod · 0.95
regressMethod · 0.95

Calls 12

setMethod · 0.95
nnzMethod · 0.95
mutableDivideMethod · 0.95
lengthMethod · 0.95
getNumericalValuesMethod · 0.80
expMethod · 0.80
getCategoricalValuesMethod · 0.80
getCategoricalDataMethod · 0.80
getQueryInfoMethod · 0.65
sizeMethod · 0.65
distMethod · 0.65
getWeightMethod · 0.45

Tested by

no test coverage detected