集册 Java实例教程 基于给定数组x和必须介于(0和x.length)之间的索引,生成介于0和1之间的双精度值

基于给定数组x和必须介于(0和x.length)之间的索引,生成介于0和1之间的双精度值

欢马劈雪     最近更新时间:2020-01-02 10:19:05

426
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
基于给定数组x和必须介于(0和x.length)之间的索引,生成介于0和1之间的双精度值


//package com.nowjava;
/** 时代Java - N o w  J a v a . c o m 提 供 **/

public class Main {

    public static void main(String[] argv) throws Exception {

        int index = 2;

        double[] x = new double[] { 34.45, 35.45, 36.67, 37.78, 37.0000,

                37.1234, 67.2344, 68.34534, 69.87700 };

        System.out.println(softmax(index, x));

    }


    /**

     * produces a double between 0 and 1 based on the given array x

     * and the index that must be between (0 and x.length)

     * For further information see also:

     * http://www-ccs.ucsd.edu/matlab/toolbox/nnet/softmax.html

     */

    public static double softmax(int index, double[] x) {

        double sum = 0;

        for (int i = 0; i
展开阅读全文