用于保存感知器数据的自定义类 – 可能未正确填充

我有以下输入

 0 0 0 0 0  0 2 0 0 0 0 1  0 2 0 0 0 1 0  0 2 0 0 0 1 1  0 2

这些是用于演示的玩具值

这些值旨在为具有两个输出的感知器提供输入,即标签前的两个标签。

我创建了一个类来保存一组输入和一个标签,因此我设想最终会有两个数据结构,每个神经元一个,形式如下:

 0 0 0 0 0  0 0 0 0 0 1  0 0 0 0 1 0  0 0 0 0 1 1  0

 0 0 0 0 0  2 0 0 0 0 1  2 0 0 0 1 0  2 0 0 0 1 1  2

该类看起来像这样:

class Group {   public String key;   public String[] value;   public String getKey() {      return key;   }   public String[] getValue() {      return value;   }   Group(String[] splited_inputs, String k)    {      this.key = k;      this.value = splited_inputs;   }   @Override   public String toString() {      return this.key + " " + this.value;   }}

我通过从文件中读取输入来填充这个类,方式如下:

      ArrayList<Group> list = new ArrayList<>();    /**************     * READ INPUT *     **************/    BufferedReader reader = new BufferedReader(new FileReader("../PA-A-train.dat"));    String line;//new variable    while ((line = reader.readLine()) != null) //read the line and compare    {        /*********************************************************************         * GET THE LINE, SPLIT ON THE TAB FOR LABEL VS. INPUT IDENTIFICATION *         *********************************************************************/        String[] label_detector = line.split("\t"); //split        /*****************************         * GET THE INDIVIDUAL INPUTS *         *****************************/        String inputs = label_detector[label_detector.length - 2];        String[] splited_inputs = inputs.split("\\s+");        splited_inputs = Arrays.stream(splited_inputs) //Remove null values                .filter(s -> (s != null && s.length() > 0))                .toArray(String[]::new);         //for this training datum, how many features does it have        int number_of_inputs = splited_inputs.length;   //5             /************************************         * GET THE LABEL (2nd LAYER OUTPUT) *         ************************************/        String trueLabel = label_detector[label_detector.length - 1];        //System.out.println("this is the corresponding label: " + trueLabel);        String[] splited_labels = trueLabel.split("\\s+");        int number_of_labels = splited_labels.length;                 list.add(new Group(splited_inputs, splited_labels[0]));    }    reader.close();    for (Group p : list)        System.out.println( "check it out: " + p.toString() );}

但是当我尝试打印时,输出看起来像这样:

check it out: 0 [Ljava.lang.String;@87aac27check it out: 0 [Ljava.lang.String;@3e3abc88check it out: 0 [Ljava.lang.String;@6ce253f1check it out: 0 [Ljava.lang.String;@53d8d10acheck it out: 0 [Ljava.lang.String;@e9e54c2check it out: 0 [Ljava.lang.String;@65ab7765check it out: 0 [Ljava.lang.String;@1b28cdfacheck it out: 1 [Ljava.lang.String;@eed1f14check it out: 0 [Ljava.lang.String;@7229724fcheck it out: 0 [Ljava.lang.String;@4c873330

所以它打印的是内存位置而不是输入数组。

这是因为我最初只插入内存位置,还是因为我没有正确迭代以正确打印它?


回答:

在Java中,你不能直接调用toString()来打印数组的内容。

但是,你可以使用Arrays.toString(Object[] arr)

@Overridepublic String toString() {   return this.key + " " + Arrays.toString(this.value);}

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注