001/* 002 * Copyright (c) 2015-2020, Oracle and/or its affiliates. All rights reserved. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.tribuo; 018 019/** 020 * Same as a {@link RealInfo}, but with an additional int id field. 021 */ 022public class RealIDInfo extends RealInfo implements VariableIDInfo { 023 private static final long serialVersionUID = 1L; 024 025 private final int id; 026 027 /** 028 * Constructs a real id info from the supplied arguments. 029 * @param name The feature name. 030 * @param count The feature occurrence count. 031 * @param max The maximum observed value. 032 * @param min The minimum observed value. 033 * @param mean The observed mean. 034 * @param sumSquares The observed sum of squared values. 035 * @param id The id number. 036 */ 037 public RealIDInfo(String name, int count, double max, double min, double mean, double sumSquares, int id) { 038 super(name,count,max,min,mean,sumSquares); 039 this.id = id; 040 } 041 042 /** 043 * Constructs a deep copy of the supplied real info and id. 044 * @param info The info to copy. 045 * @param id The new id number. 046 */ 047 public RealIDInfo(RealInfo info, int id) { 048 super(info); 049 this.id = id; 050 } 051 052 /** 053 * Copies the supplied real id info, renaming the feature. 054 * @param info The info to copy. 055 * @param newName The new name. 056 */ 057 private RealIDInfo(RealIDInfo info, String newName) { 058 super(info,newName); 059 this.id = info.id; 060 } 061 062 @Override 063 public int getID() { 064 return id; 065 } 066 067 @Override 068 public RealIDInfo makeIDInfo(int id) { 069 return new RealIDInfo(this,id); 070 } 071 072 @Override 073 public RealIDInfo rename(String newName) { 074 return new RealIDInfo(this,newName); 075 } 076 077 @Override 078 public RealIDInfo copy() { 079 return new RealIDInfo(this,name); 080 } 081 082 @Override 083 public String toString() { 084 return String.format("RealFeature(name=%s,id=%d,count=%d,max=%f,min=%f,mean=%f,variance=%f)",name,id,count,max,min,mean,(sumSquares /(count-1))); 085 } 086}