-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
253 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version=7.4.0-BETA | ||
version=7.4.0 | ||
group=com.rapidminer.studio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/main/java/com/rapidminer/example/set/FullAttributeTransformationRemapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* Copyright (C) 2001-2017 by RapidMiner and the contributors | ||
* | ||
* Complete list of developers available at our web site: | ||
* | ||
* http://rapidminer.com | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms of the | ||
* GNU Affero General Public License as published by the Free Software Foundation, either version 3 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License along with this program. | ||
* If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.rapidminer.example.set; | ||
|
||
import com.rapidminer.example.Attribute; | ||
import com.rapidminer.example.AttributeTransformation; | ||
import com.rapidminer.example.AttributeTypeException; | ||
import com.rapidminer.example.table.NominalMapping; | ||
|
||
|
||
/** | ||
* This transformation returns the remapped value, remapping from the given {@link #baseMapping} to | ||
* the current mapping of the attribute. {@link #transform(Attribute, double)} maps the given double | ||
* value to a tranformed value that represents the same nominal value in the current attribute | ||
* mapping as the given value represents in the {@link #baseMapping}. This transformation should be | ||
* used if the mapping of an attribute is changed. In that case, use the old mapping as | ||
* {@link #baseMapping} in this transformation. | ||
* | ||
* @author Ingo Mierswa, Gisa Schaefer | ||
* @since 7.4 | ||
*/ | ||
public class FullAttributeTransformationRemapping implements AttributeTransformation { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private NominalMapping baseMapping; | ||
|
||
public FullAttributeTransformationRemapping(NominalMapping baseMapping) { | ||
this.baseMapping = baseMapping; | ||
} | ||
|
||
public FullAttributeTransformationRemapping(FullAttributeTransformationRemapping other) { | ||
this.baseMapping = (NominalMapping) other.baseMapping.clone(); | ||
} | ||
|
||
@Override | ||
public Object clone() { | ||
return new FullAttributeTransformationRemapping(this); | ||
} | ||
|
||
public void setNominalMapping(NominalMapping mapping) { | ||
this.baseMapping = mapping; | ||
} | ||
|
||
@Override | ||
public double transform(Attribute attribute, double value) { | ||
if (Double.isNaN(value)) { | ||
return value; | ||
} | ||
if (attribute.isNominal()) { | ||
try { | ||
String nominalValue = baseMapping.mapIndex((int) value); | ||
int index = attribute.getMapping().getIndex(nominalValue); | ||
if (index < 0) { | ||
return Double.NaN; | ||
} else { | ||
return index; | ||
} | ||
} catch (AttributeTypeException e) { | ||
return Double.NaN; | ||
} | ||
} else { | ||
return value; | ||
} | ||
} | ||
|
||
@Override | ||
public double inverseTransform(Attribute attribute, double value) { | ||
if (Double.isNaN(value)) { | ||
return value; | ||
} | ||
if (attribute.isNominal()) { | ||
try { | ||
String nominalValue = attribute.getMapping().mapIndex((int) value); | ||
int newValue = baseMapping.getIndex(nominalValue); | ||
if (newValue < 0) { | ||
return value; | ||
} else { | ||
return newValue; | ||
} | ||
} catch (AttributeTypeException e) { | ||
return value; | ||
} | ||
} else { | ||
return value; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isReversable() { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.