Java Bipolar to Double bipolar2double(final boolean b)

Here you can find the source of bipolar2double(final boolean b)

Description

bipolardouble

License

Open Source License

Declaration

public static double bipolar2double(final boolean b) 

Method Source Code

//package com.java2s;
/**//from  w  ww  .j ava 2s  .  c o  m
 * Introduction to Neural Networks with Java, 2nd Edition
 * Copyright 2008 by Heaton Research, Inc. 
 * http://www.heatonresearch.com/books/java-neural-2/
 * 
 * ISBN13: 978-1-60439-008-7      
 * ISBN:   1-60439-008-5
 *   
 * This class is released under the:
 * GNU Lesser General Public License (LGPL)
 * http://www.gnu.org/copyleft/lesser.html
 */

public class Main {
    public static double bipolar2double(final boolean b) {
        if (b) {
            return 1;
        } else {
            return -1;
        }
    }

    public static double[] bipolar2double(final boolean b[]) {
        final double[] result = new double[b.length];

        for (int i = 0; i < b.length; i++) {
            result[i] = bipolar2double(b[i]);
        }

        return result;
    }

    public static double[][] bipolar2double(final boolean b[][]) {
        final double[][] result = new double[b.length][b[0].length];

        for (int row = 0; row < b.length; row++) {
            for (int col = 0; col < b[0].length; col++) {
                result[row][col] = bipolar2double(b[row][col]);
            }
        }

        return result;
    }
}