package cs437.som.neighborhood;

import cs437.som.NeighborhoodWidthFunction;

/**
 * Hyperbolic neighborhood width strategy for self-organizing map.
 *
 * <pre>
 * The exact behavior follows the formula:
 *      w_0 \cdot (\frac{w_{final}}{w_0})^\frac{t}{t_{max}}
 *  where
 *      w_0       is the learning rate at the first iteration
 *      w_{final} is the learning rate at the last iteration
 *      t              is the current iteration
 *      t_{max}        is the maximum expected iteration
 * </pre>
 */
public class HyperbolicNeighborhoodWidthFunction
        implements NeighborhoodWidthFunction {
    private double expectedIterations = 0.0;
    private final double initialWidth;
    private final double widthRatio;
    private final double finalWidth;

    /**
     * Create an hyperbolic neighborhood width function.
     *
     * @param initialWidth The initial width of the neighborhood.
     * @param finalWidth The final width of the neighborhood.
     */
    public HyperbolicNeighborhoodWidthFunction(double initialWidth,
                                               double finalWidth) {
        this.initialWidth = initialWidth;
        this.finalWidth = finalWidth;
        widthRatio = finalWidth / initialWidth;
    }

    public void setExpectedIterations(int expectedIterations) {
        this.expectedIterations = expectedIterations;
    }

    public double neighborhoodWidth(int iteration) {
        return initialWidth * Math.pow(widthRatio, (iteration / expectedIterations));
    }

    @Override
    public String toString() {
        return "HyperbolicNeighborhoodWidthFunction " + initialWidth + ' ' + finalWidth;
    }
}

@@ -1653,11 +1653,304 @@
 h;%0A    %7D
+%0A%0A    public HyperbolicNeighborhoodWidthFunction(String parameters) %7B%0A        String%5B%5D arguments = parameters.split(%22%5C%5Cs*%22, 2);%0A        initialWidth = Double.parseDouble(arguments%5B0%5D);%0A        finalWidth = Double.parseDouble(arguments%5B1%5D);%0A        widthRatio = finalWidth / initialWidth;%0A    %7D
 %0A%7D%0A

Add String constructor to HyperbolicNeighborhoodWidthFunction.