@@ -0,0 +1,2943 @@
+package cs437.som.neighborhood;%0A%0Aimport cs437.som.NeighborhoodWidthFunction;%0A%0Aimport java.util.*;%0A%0A/**%0A * Collects a series of neighborhood width functions to be used sequentially in%0A * training a SOM.  This allows a SOM to be trained with a large, linearly%0A * decreasing neighborhood width initially and, afterwards, the width function%0A * can change to a exponentially decreasing function.  Any number of%0A * combinations should be possible.%0A *%0A * Using neighborhood width functions in a CompoundNeighborhood is an exception%0A * to the instructions given in the NeighborhoodWidthFunction interface%0A * documentation:%0A *%0A * The NeighborhoodWidthFunction object should have its expected iterations%0A * property set before it is added to a CompoundNeighborhood object.%0A *%0A * Once a NeighborhoodWidthFunction has been added to a CompoundNeighborhood%0A * object, its ownership is passed to the CompoundNeighborhood object ad should%0A * not be modified by the user afterward.%0A */%0Apublic class CompoundNeighborhood implements NeighborhoodWidthFunction %7B%0A    private int nextTransition = -1;%0A%0A    private NeighborhoodWidthFunction currentFunction;%0A%0A    private Map%3CInteger, NeighborhoodWidthFunction%3E widthFunctions%0A            = new HashMap%3CInteger, NeighborhoodWidthFunction%3E(2);%0A%0A    public CompoundNeighborhood(NeighborhoodWidthFunction initialWidthFuncton) %7B%0A        widthFunctions.put(0, initialWidthFuncton);%0A        currentFunction = initialWidthFuncton;%0A    %7D%0A%0A    public void setExpectedIterations(int expectedIterations) %7B%0A        if (nextTransition == -1) %7B%0A            nextTransition = expectedIterations;%0A        %7D%0A    %7D%0A%0A    public double neighborhoodWidth(int iteration) %7B%0A        if (iteration == nextTransition) %7B%0A            shiftFunctions();%0A        %7D%0A        return currentFunction.neighborhoodWidth(iteration);%0A    %7D%0A%0A    /**%0A     * Add a neighborhood function to be used after a specific number of%0A     * iterations.%0A     *%0A     * @param neighborhood The neighborhood function object to add.%0A     * @param startAt The iteration at which to use %7B@code neighborhood%7D.%0A     */%0A    public void addNeighborhood(NeighborhoodWidthFunction neighborhood, int startAt) %7B%0A        widthFunctions.put(startAt, neighborhood);%0A    %7D%0A%0A    /**%0A     * Find the next neighborhood width function shift it into the current%0A     * slot.%0A     */%0A    private void shiftFunctions() %7B%0A        // Don't try to shift if there's nothing left to use.%0A        if (widthFunctions.isEmpty()) %7B%0A            return;%0A        %7D%0A%0A        // Find the next lowest transition point%0A        int low = nextTransition;%0A        for (Integer i : widthFunctions.keySet()) %7B%0A            if (i %3C low) %7B%0A                low = i;%0A            %7D%0A        %7D%0A%0A        // Move the next function into place.%0A        currentFunction = widthFunctions.remove(low);%0A        nextTransition = low;%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        return %22CompoundNeighborhood%22;%0A    %7D%0A%7D%0A

Add CompoundNeighborhood to sequence neighborhood functions.