Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
Mustic
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lafabregue
Mustic
Commits
bae79103
Commit
bae79103
authored
May 02, 2018
by
lafabregue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test program modification
parent
048cfaef
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
16 deletions
+85
-16
src/test/TestA2CNESIterative.java
src/test/TestA2CNESIterative.java
+85
-16
No files found.
src/test/TestA2CNESIterative.java
View file @
bae79103
package
test
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.nio.file.DirectoryStream
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
...
...
@@ -20,7 +23,16 @@ import jcl.clustering.constraints.CannotLinkConstraint;
import
jcl.clustering.constraints.Constraint
;
import
jcl.clustering.constraints.MustLinkConstraint
;
import
jcl.data.Data
;
import
jcl.data.Model
;
import
jcl.data.SimpleData
;
import
jcl.data.attribute.AttributeMultiDimSequence
;
import
jcl.data.distance.Distance
;
import
jcl.data.distance.DistanceParameter
;
import
jcl.data.distance.EmptyDistanceParameter
;
import
jcl.data.distance.MetaDistance
;
import
jcl.data.distance.MetaDistanceEuclidean
;
import
jcl.data.distance.NumericalEuclideanDistance
;
import
jcl.data.distance.sequential.ParameterDTW
;
import
jcl.data.mask.IntArrayMask
;
import
jcl.data.mask.Mask
;
import
jcl.io.results.CSVResultWriter
;
...
...
@@ -38,14 +50,21 @@ public class TestA2CNESIterative {
public
static
void
main
(
String
[]
args
)
{
HybridClassification
classification
=
new
HybridClassification
();
final
String
datasetName
=
"ElectricDevices"
;
final
String
datasetPath
=
"ElectricDevices"
;
final
String
dataPath
=
"/home/baptiste/A2CNES/"
;
final
String
resultPath
=
"/home/baptiste/A2CNES/results_iter/"
;
// String testResultPath = "/home/baptiste/A2CNES/Train_results/";
final
String
datasetName
=
"FacesUCR"
;
final
String
datasetPath
=
"FacesUCR"
;
final
String
dataPath
=
"~/A2CNES/"
;
final
String
resultPath
=
"~/A2CNES/results_iter/"
;
final
int
nInf
=
12
;
final
int
nSup
=
17
;
final
int
ag1_seeds
=
16
;
final
int
ag2_seeds
=
20
;
final
int
ag3_seeds
=
24
;
final
int
nb_iter
=
15
;
// String testResultPath = "~/A2CNES/Train_results/";
// Data dataTrain = TestA2CNES.getDataFromFile(dataPath+datasetPath+"/train/"+datasetName+".data", '\t', "train", null);
Data
dataTest
=
TestA2CNES
.
getDataFromFile
(
dataPath
+
datasetPath
+
"/test/"
+
datasetName
+
".data"
,
'\t'
,
"test"
,
null
);
final
Data
dataTest
=
TestA2CNES
.
getDataFromFile
(
dataPath
+
datasetPath
+
"/test/"
+
datasetName
+
".data"
,
'\t'
,
"test"
,
null
);
// AttributeMultiDimSequence.setMode(AttributeMultiDimSequence.EUCLIDIEN);
...
...
@@ -53,8 +72,6 @@ public class TestA2CNESIterative {
final
DateTime
startTime
=
DateTime
.
now
();
int
nInf
=
6
;
int
nSup
=
9
;
// parametre pour la precision des conflits
final
double
minC
=
0.9
;
...
...
@@ -65,7 +82,7 @@ public class TestA2CNESIterative {
// parametre qualite/similitude
final
double
ps
=
0.2
;
final
double
pq
=
1.0
-
ps
;
final
double
constraintsWgt
=
8
0
;
final
double
constraintsWgt
=
0
;
final
double
valueKExtern
=
60
;
final
double
kExtern
=
valueKExtern
*
((
100
-
constraintsWgt
)/
100
);
final
double
kIntern
=
(
100
-
valueKExtern
)
*
((
100
-
constraintsWgt
)/
100
);
...
...
@@ -181,19 +198,19 @@ public class TestA2CNESIterative {
e
.
printStackTrace
();
}
final
int
subsetSize
=
(
int
)
Math
.
ceil
(
constraints
.
size
()
*
0.0
5
);
final
int
subsetSize
=
(
int
)
Math
.
ceil
(
constraints
.
size
()
*
0.0
4
);
for
(
int
i
=
0
;
i
<
1
;
i
++)
{
final
HybridClassification
classif
=
(
HybridClassification
)
classification
.
clone
();
Data
currentData
=
(
Data
)
dataTest
.
clone
();
final
Vector
<
Constraint
>
subset
=
new
Vector
<
Constraint
>();
extractAndAddConstraints
(
subset
,
constraints
,
subsetSize
,
null
);
currentData
.
updateAndSetConstraintsToSample
(
subset
);
//
extractAndAddConstraints(subset, constraints, subsetSize, null);
//
currentData.updateAndSetConstraintsToSample(subset);
classif
.
addAgent
(
new
ParametersKmeans
(
7
,
15
,
weights
),
currentData
);
classif
.
addAgent
(
new
ParametersKmeans
(
11
,
15
,
weights
),
currentData
);
classif
.
addAgent
(
new
ParametersKmeans
(
14
,
15
,
weights
),
currentData
);
classif
.
addAgent
(
new
ParametersKmeans
(
ag1_seeds
,
nb_iter
,
weights
),
currentData
);
classif
.
addAgent
(
new
ParametersKmeans
(
ag2_seeds
,
nb_iter
,
weights
),
currentData
);
classif
.
addAgent
(
new
ParametersKmeans
(
ag3_seeds
,
nb_iter
,
weights
),
currentData
);
final
String
path_to_add
=
resultPath
+
datasetName
+
"/"
;
classif
.
setName
(
ImageHelper
.
stripExtension
(
filename
)+
"-"
+
i
+
...
...
@@ -214,6 +231,25 @@ public class TestA2CNESIterative {
e
.
printStackTrace
();
}
System
.
out
.
println
(
"First classification completed"
);
FileWriter
fw
=
null
;
try
{
fw
=
new
FileWriter
(
"log_cst"
+
classif
.
getName
()+
".log"
,
true
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
BufferedWriter
bw
=
new
BufferedWriter
(
fw
);
PrintWriter
out
=
new
PrintWriter
(
bw
);
Distance
[]
distances
=
new
Distance
[
1
];
// a distance is set for every attribute
distances
[
0
]
=
jcl
.
data
.
distance
.
sequential
.
DistanceDTW
.
getInstance
();
// second attribute (sequential) compared with the DTW distance
MetaDistance
metaDistance
=
MetaDistanceEuclidean
.
getInstance
();
// defines the way the two scores are combined (possibility to weight)
Model
model
=
new
Model
(
distances
,
metaDistance
);
int
seqLength
=
((
AttributeMultiDimSequence
)
dataTest
.
getOneDataObject
().
getAttribute
(
0
)).
sequence
.
length
;
DistanceParameter
[]
distanceParameters
=
new
DistanceParameter
[
1
];
distanceParameters
[
0
]
=
new
ParameterDTW
(
new
double
[
seqLength
][
seqLength
]);
//but yes for DTW (requires a matrix to work in)
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
int
[]
clustMap
=
classif
.
getClusteringResult
().
getClusterMap
();
int
[]
satisifiedMap
=
new
int
[
constraints
.
size
()];
...
...
@@ -230,10 +266,36 @@ public class TestA2CNESIterative {
satisifiedMap
[
j
]
=
1
;
}
}
Mask
satisfactionMask
=
new
IntArrayMask
(
satisifiedMap
,
1
,
true
);
extractAndAddConstraints
(
subset
,
constraints
,
subsetSize
,
satisfactionMask
);
out
.
println
(
"------- new iter : "
+
(
i
+
1
)
+
" --------"
);
for
(
Constraint
c
:
constraints
)
{
if
(
c
instanceof
MustLinkConstraint
)
{
MustLinkConstraint
ml
=
(
MustLinkConstraint
)
c
;
out
.
println
(
c
.
toString
()+
";"
+
Constraint
.
marginalSilhouetteScore
(
ml
.
getFirstIndex
(),
classif
.
getClusteringResult
(),
model
,
distanceParameters
)+
";"
+
Constraint
.
marginalSilhouetteScore
(
ml
.
getSecondIndex
(),
classif
.
getClusteringResult
(),
model
,
distanceParameters
)
);
}
else
{
CannotLinkConstraint
cl
=
(
CannotLinkConstraint
)
c
;
out
.
println
(
c
.
toString
()+
";"
+
Constraint
.
marginalSilhouetteScore
(
cl
.
getFirstIndex
(),
classif
.
getClusteringResult
(),
model
,
distanceParameters
)+
";"
+
Constraint
.
marginalSilhouetteScore
(
cl
.
getSecondIndex
(),
classif
.
getClusteringResult
(),
model
,
distanceParameters
)
);
}
}
classif
.
setAdvancedParameters
(
degradation
,
classRatio
,
solutionType
,
kIntern
,
kExtern
,
unificationType
,
criterion
,
9
0
);
kExtern
,
unificationType
,
criterion
,
9
5
);
classif
.
newIteration
(
subset
);
try
{
...
...
@@ -243,6 +305,13 @@ public class TestA2CNESIterative {
}
System
.
out
.
println
(
"Iteration "
+(
i
+
1
)+
" completed"
);
}
try
{
out
.
close
();
bw
.
close
();
fw
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
};
t
.
start
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment