Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Iobber
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Syntactic Tools
Chunking
Iobber
Commits
9c2168ac
Commit
9c2168ac
authored
Jul 3, 2013
by
Adam Pawlaczek
Browse files
Options
Downloads
Patches
Plain Diff
changed anneal.py
parent
686e653b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/chunker_scripts/feature_selection/anneal.py
+38
-11
38 additions, 11 deletions
scripts/chunker_scripts/feature_selection/anneal.py
with
38 additions
and
11 deletions
scripts/chunker_scripts/feature_selection/anneal.py
+
38
−
11
View file @
9c2168ac
...
@@ -7,13 +7,15 @@ Created on 08-04-2013
...
@@ -7,13 +7,15 @@ Created on 08-04-2013
'''
'''
import
random
import
random
import
os
import
os
import
math
class
AnnealOptimalizer
():
class
AnnealOptimalizer
():
def
__init__
(
self
,
func
,
a_vector
,
args
,
T0
,
Tf
=
1e-12
,
maxiter
=
400
,
temp_reducing_rate
=
0.95
,
changing_features
=
2
,
opt
=
"
min
"
,
verbose
=
False
):
def
__init__
(
self
,
func
,
a_vector
,
args
,
seed
,
T0
,
Tf
=
1e-12
,
maxiter
=
400
,
temp_reducing_rate
=
0.95
,
changing_features
=
2
,
opt
=
"
min
"
,
verbose
=
False
):
self
.
func
=
func
self
.
func
=
func
self
.
a_vector
=
a_vector
self
.
a_vector
=
a_vector
self
.
args
=
args
self
.
args
=
args
self
.
out_dir
=
args
[
'
out_dir
'
]
if
T0
==
None
:
if
T0
==
None
:
raise
IOError
(
'
You have to set some T0
'
)
raise
IOError
(
'
You have to set some T0
'
)
self
.
T0
=
T0
self
.
T0
=
T0
...
@@ -24,6 +26,8 @@ class AnnealOptimalizer():
...
@@ -24,6 +26,8 @@ class AnnealOptimalizer():
self
.
opt
=
opt
self
.
opt
=
opt
self
.
verbose
=
verbose
self
.
verbose
=
verbose
random
.
seed
(
seed
)
def
P
(
self
,
e
,
en
,
temp
):
def
P
(
self
,
e
,
en
,
temp
):
print
"
e:
"
,
e
,
"
en:
"
,
en
print
"
e:
"
,
e
,
"
en:
"
,
en
if
self
.
opt
==
"
min
"
:
if
self
.
opt
==
"
min
"
:
...
@@ -63,15 +67,17 @@ class AnnealOptimalizer():
...
@@ -63,15 +67,17 @@ class AnnealOptimalizer():
iterations
=
100
#ilosc iteracji symulacji
iterations
=
100
#ilosc iteracji symulacji
sum
=
0
sum
=
0
results
=
{}
#histogram wyników
results
=
{}
#histogram wyników
for
i
in
range
(
iterations
):
for
i
in
range
(
iterations
):
if
'
out_dir
'
in
self
.
args
:
self
.
args
[
'
out_dir
'
]
=
os
.
path
.
join
(
self
.
out_dir
,
"
tempest
"
,
str
(
i
))
result
=
self
.
func
(
vector
,
self
.
args
)
result
=
self
.
func
(
vector
,
self
.
args
)
sum
+=
result
sum
+=
result
if
result
not
in
results
.
keys
():
if
result
not
in
results
.
keys
():
results
[
result
]
=
1
results
[
result
]
=
1
else
:
else
:
results
[
result
]
+=
1
results
[
result
]
+=
1
vector
=
neightbour
(
vector
)
vector
=
self
.
neightbour
(
vector
)
avg
=
sum
/
float
(
iterations
)
#obliczenie średniego wyniku
avg
=
sum
/
float
(
iterations
)
#obliczenie średniego wyniku
k
=
0
k
=
0
deviation
=
0
deviation
=
0
...
@@ -85,18 +91,16 @@ class AnnealOptimalizer():
...
@@ -85,18 +91,16 @@ class AnnealOptimalizer():
def
anneal
(
self
):
def
anneal
(
self
):
temperature
=
self
.
T0
temperature
=
self
.
T0
i
=
0
i
=
0
out_dir
=
self
.
args
[
'
out_dir
'
]
if
'
out_dir
'
in
self
.
args
:
self
.
args
[
'
out_dir
'
]
=
os
.
path
.
join
(
out_dir
,
str
(
i
))
a_vector
=
self
.
a_vector
a_vector
=
self
.
a_vector
self
.
args
[
'
out_dir
'
]
=
os
.
path
.
join
(
self
.
out_dir
,
"
selection
"
,
str
(
i
))
a_value
=
self
.
func
(
a_vector
,
self
.
args
)
a_value
=
self
.
func
(
a_vector
,
self
.
args
)
b_value
=
None
b_value
=
None
i
+=
1
i
+=
1
while
temperature
>
self
.
Tf
and
i
<
self
.
maxiter
:
while
temperature
>
self
.
Tf
and
i
<
self
.
maxiter
:
if
'
out_dir
'
in
self
.
args
.
keys
()
:
if
'
out_dir
'
in
self
.
args
:
self
.
args
[
'
out_dir
'
]
=
os
.
path
.
join
(
out_dir
,
i
)
self
.
args
[
'
out_dir
'
]
=
os
.
path
.
join
(
self
.
out_dir
,
"
selection
"
,
str
(
i
))
b_vector
=
self
.
neightbour
(
a_vector
)
b_vector
=
self
.
neightbour
(
a_vector
)
b_value
=
self
.
func
(
b_vector
,
self
.
args
)
b_value
=
self
.
func
(
b_vector
,
self
.
args
)
p
=
self
.
P
(
a_value
,
b_value
,
temperature
)
p
=
self
.
P
(
a_value
,
b_value
,
temperature
)
...
@@ -114,9 +118,31 @@ class AnnealOptimalizer():
...
@@ -114,9 +118,31 @@ class AnnealOptimalizer():
i
+=
1
i
+=
1
return
(
a_vector
,
a_value
)
return
(
a_vector
,
a_value
)
def
calculate_temp
(
self
):
sum
=
0
results
=
[]
for
(
path
,
dirs
,
files
)
in
os
.
walk
(
os
.
path
.
join
(
self
.
out_dir
,
"
tempest
"
)):
for
file
in
files
:
if
os
.
path
.
basename
(
file
)
==
"
result.csv
"
:
f
=
open
(
os
.
path
.
join
(
path
,
file
),
'
r
'
)
line
=
f
.
readline
()
line
=
f
.
readline
()
fmeasure
=
float
(
line
.
split
(
"
:
"
)[
4
][:
-
1
].
strip
())
results
.
append
(
fmeasure
)
sum
+=
fmeasure
f
.
close
()
avg
=
sum
/
float
(
len
(
results
))
k
=
0
deviation
=
0
for
result
in
results
:
deviation
+=
result
*
((
k
-
avg
)
**
2
)
k
+=
1
self
.
T0
=
math
.
sqrt
(
deviation
/
len
(
results
))
return
self
.
T0
def
main
(
func
,
a_vector
,
args
=
{},
T0
=
None
,
Tf
=
1e-12
,
maxiter
=
400
,
temp_reducing_rate
=
0.95
,
changing_features
=
2
,
opt
=
"
min
"
):
def
main
(
func
,
a_vector
,
args
=
{},
T0
=
None
,
Tf
=
1e-12
,
maxiter
=
400
,
temp_reducing_rate
=
0.95
,
changing_features
=
2
,
opt
=
"
min
"
):
ao
=
AnnealOptimalizer
(
func
,
a_vector
,
args
,
T0
,
Tf
,
maxiter
,
temp_reducing_rate
,
changing_features
,
opt
)
ao
=
AnnealOptimalizer
(
func
,
a_vector
,
args
,
T0
,
Tf
,
maxiter
,
temp_reducing_rate
,
changing_features
,
opt
)
print
ao
.
anneal
()
ao
.
anneal
()
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
def
func
(
v
,
args
):
def
func
(
v
,
args
):
...
@@ -131,3 +157,4 @@ if __name__ == '__main__':
...
@@ -131,3 +157,4 @@ if __name__ == '__main__':
a
=
[
False
,
False
,
False
,
False
,
False
,
False
,
False
]
a
=
[
False
,
False
,
False
,
False
,
False
,
False
,
False
]
main
(
func
,
a
,
args
=
{},
T0
=
0.1
,
Tf
=
1e-12
,
maxiter
=
200
,
temp_reducing_rate
=
0.95
,
changing_features
=
2
,
opt
=
"
max
"
)
main
(
func
,
a
,
args
=
{},
T0
=
0.1
,
Tf
=
1e-12
,
maxiter
=
200
,
temp_reducing_rate
=
0.95
,
changing_features
=
2
,
opt
=
"
max
"
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment