|
Java example source code file (KohonenUpdateAction.java)
The KohonenUpdateAction.java Java example source code/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.math3.ml.neuralnet.sofm; import java.util.Collection; import java.util.HashSet; import java.util.concurrent.atomic.AtomicLong; import org.apache.commons.math3.analysis.function.Gaussian; import org.apache.commons.math3.linear.ArrayRealVector; import org.apache.commons.math3.ml.distance.DistanceMeasure; import org.apache.commons.math3.ml.neuralnet.MapUtils; import org.apache.commons.math3.ml.neuralnet.Network; import org.apache.commons.math3.ml.neuralnet.Neuron; import org.apache.commons.math3.ml.neuralnet.UpdateAction; /** * Update formula for <a href="http://en.wikipedia.org/wiki/Kohonen"> * Kohonen's Self-Organizing Map</a>. * <br/> * The {@link #update(Network,double[]) update} method modifies the * features {@code w} of the "winning" neuron and its neighbours * according to the following rule: * <code> * w<sub>new = wold + ? e(-d / ?) * (sample - wold) * </code> * where * <ul> * <li>? is the current learning rate, * <li>? is the current neighbourhood size, and * <li>{@code d} is the number of links to traverse in order to reach * the neuron from the winning neuron.</li> * </ul> * <br/> * This class is thread-safe as long as the arguments passed to the * {@link #KohonenUpdateAction(DistanceMeasure,LearningFactorFunction, * NeighbourhoodSizeFunction) constructor} are instances of thread-safe * classes. * <br/> * Each call to the {@link #update(Network,double[]) update} method * will increment the internal counter used to compute the current * values for * <ul> * <li>the learning rate, and * <li>the neighbourhood size. * </ul> * Consequently, the function instances that compute those values (passed * to the constructor of this class) must take into account whether this * class's instance will be shared by multiple threads, as this will impact * the training process. * * @since 3.3 */ public class KohonenUpdateAction implements UpdateAction { /** Distance function. */ private final DistanceMeasure distance; /** Learning factor update function. */ private final LearningFactorFunction learningFactor; /** Neighbourhood size update function. */ private final NeighbourhoodSizeFunction neighbourhoodSize; /** Number of calls to {@link #update(Network,double[])}. */ private final AtomicLong numberOfCalls = new AtomicLong(0); /** * @param distance Distance function. * @param learningFactor Learning factor update function. * @param neighbourhoodSize Neighbourhood size update function. */ public KohonenUpdateAction(DistanceMeasure distance, LearningFactorFunction learningFactor, NeighbourhoodSizeFunction neighbourhoodSize) { this.distance = distance; this.learningFactor = learningFactor; this.neighbourhoodSize = neighbourhoodSize; } /** * {@inheritDoc} */ public void update(Network net, double[] features) { final long numCalls = numberOfCalls.incrementAndGet() - 1; final double currentLearning = learningFactor.value(numCalls); final Neuron best = findAndUpdateBestNeuron(net, features, currentLearning); final int currentNeighbourhood = neighbourhoodSize.value(numCalls); // The farther away the neighbour is from the winning neuron, the // smaller the learning rate will become. final Gaussian neighbourhoodDecay = new Gaussian(currentLearning, 0, currentNeighbourhood); if (currentNeighbourhood > 0) { // Initial set of neurons only contains the winning neuron. Collection<Neuron> neighbours = new HashSet Other Java examples (source code examples)Here is a short list of links related to this Java KohonenUpdateAction.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.