Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mlassign2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sushant Mahajan
mlassign2
Commits
c6d699cc
Commit
c6d699cc
authored
Apr 09, 2016
by
Sushant Mahajan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created weight matrices
parent
64bb590d
Pipeline
#275
skipped
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
7 deletions
+40
-7
model.py
model.py
+40
-7
No files found.
model.py
View file @
c6d699cc
...
...
@@ -2,27 +2,60 @@
import
sys
import
os
import
csv
from
random
import
random
from
pprint
import
pprint
as
pp
params
=
{
"layers"
:[
57
,
57
*
2
,
1
],
"test"
:
"TestX.csv"
,
"train"
:
"Train.csv"
}
params
=
{
"layers"
:[
57
,
int
(
57
/
2
)
,
1
],
"test"
:
"TestX.csv"
,
"train"
:
"Train.csv"
}
def
getData
(
srcF
,
isTrain
=
True
):
def
getData
(
srcF
,
isTrain
=
True
,
addBias
=
True
):
X
,
y
=
[],[]
with
open
(
srcF
)
as
src
:
reader
=
csv
.
reader
(
src
,
delimiter
=
','
)
for
i
,
row
in
enumerate
(
reader
):
temp
=
[]
if
addBias
:
temp
.
append
(
1
)
end
=
-
1
if
isTrain
else
len
(
row
)
X
.
app
end
(
row
[:
end
])
temp
.
ext
end
(
row
[:
end
])
#correct data type
X
[
i
]
=
[
x
for
x
in
map
(
float
,
X
[
i
][:
-
2
])]
X
[
i
]
.
extend
([
int
(
X
[
i
][
-
2
]),
int
(
X
[
i
][
-
1
])])
X
.
append
([
x
for
x
in
map
(
float
,
temp
)])
if
isTrain
:
y
.
append
(
int
(
row
[
-
1
]))
return
(
X
,
y
)
def
getMatrix
(
r
,
c
,
vec
):
mat
=
[]
for
i
in
range
(
r
):
temp
=
[]
for
j
in
range
(
c
):
idx
=
i
*
(
c
)
+
j
temp
.
append
(
vec
[
j
])
mat
.
append
(
temp
)
return
mat
def
cost
(
li
,
lh
,
lo
,
weights
,
X
,
y
):
w1t
=
weights
[:(
li
+
1
)
*
lh
]
#28x58
w2t
=
weights
[(
li
+
1
)
*
lh
:]
#1x29
w1
,
w2
=
getMatrix
(
lh
,
li
+
1
,
w1t
),
getMatrix
(
lo
,
lh
+
1
,
w2t
)
if
__name__
==
"__main__"
:
X
,
y
=
getData
(
params
[
"train"
])
tX
,
ty
=
getData
(
params
[
"test"
],
isTrain
=
False
)
# tX,ty = getData(params["test"], isTrain=False)
print
(
len
(
X
),
len
(
X
[
0
]),
len
(
y
),
X
[
0
])
li
,
lh
,
lo
=
tuple
(
params
[
"layers"
])
weights
=
[
random
()
for
_
in
range
(
lh
*
(
li
+
1
)
+
lo
*
(
lh
+
1
))]
w1
,
w2
=
cost
(
li
,
lh
,
lo
,
weights
,
X
,
y
)
#print(len(w1), len(w1[0]), len(w2), len(w2[0]))
\ No newline at end of file
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