I constructed the nn model using itorch notebook.
model = nn.Sequential()
model:add(nn.Reshape(ninputs))
model:add(nn.Linear(ninputs,noutputs))
Input data to the model
output = model:forward(input)
Then, I print the model and got this.
print(model)
nn.Sequential {
[input -> (1) -> (2) -> output]
(1): nn.Reshape(3072)
(2): nn.Linear(3072 -> 10)
}
{
gradInput : DoubleTensor - empty
modules :
{
1 :
nn.Reshape(3072)
{
_input : DoubleTensor - empty
nelement : 3072
train : true
output : DoubleTensor - size: 3072
gradInput : DoubleTensor - empty
size : LongStorage - size: 1
_gradOutput : DoubleTensor - empty
batchsize : LongStorage - size: 2
}
2 :
nn.Linear(3072 -> 10)
{
gradBias : DoubleTensor - size: 10
weight : DoubleTensor - size: 10x3072
train : true
bias : DoubleTensor - size: 10
gradInput : DoubleTensor - empty
gradWeight : DoubleTensor - size: 10x3072
output : DoubleTensor - size: 10
}
}
train : true
output : DoubleTensor - size: 10
}
how to read the weight in nn.linear ?
Thanks in advance.
Oh, it is similar to php
model.modules[2].weight
I find that model.modules[1].weight is similar to model:get(1).weight, but both can't get the parameters from the table layer like residual block. In this way the residual block as a layer.
however, we can use params, gradParams = model:parameters() to get the parameters for each layer even in the table layer.
It is worth noting that, in the second way, each layer of the network parameters are divided into two layers and arranged in layers
Related
I having problem with program which is prints to standard outputs. The method I test is print to standard output so it having Unit return type. I then writing Scalatest to assert output but I don't know how. I get error like this
This is output of Scalatest
Customer 1 : 20.0
Customer 2 : 20.0
Customer 3 : 20.0
Customer 4 : 20.0
Customer 5 : 20.0
<(), the Unit value> did not equal "Customer 1 : 20.0
Customer 2 : 20.0
Customer 3 : 20.0
Customer 4 : 20.0
Customer 5 : 20.0"
My assert looking like
assert(output() == "Customer 1 : 20.0\nCustomer 2 : 20.0\nCustomer 3 : 20.0\nCustomer 4 : 20.0\nCustomer 5 : 20.0")
How can I testing this?
Console.withOut enables temporary redirection of output to a stream that we can assert on, for example,
class OutputSpec extends FlatSpec with Matchers {
val someStr =
"""
|Customer 1 : 20.0
|Customer 2 : 20.0
|Customer 3 : 20.0
|Customer 4 : 20.0
|Customer 5 : 20.0
""".stripMargin
def output(): Unit = println(someStr)
"Output" should "print customer information" in {
val stream = new java.io.ByteArrayOutputStream()
Console.withOut(stream) { output() }
assert(stream.toString contains someStr)
}
}
ZERO experience, so bear with me...
Im trying to retrieve data from a Firebase Realtime Database and im using this code..
func fetchData(){
refHandle = ref?.child("caddata").observe(.childAdded, with: { (snapshot) in
if let values = snapshot.value as? [AnyHashable: Any] {
for value in values.values {
print (value)
"values" shows the following:
▿ 1 element
▿ 0 : 2 elements
▿ key : AnyHashable("parsedContent")
- value : "parsedContent"
▿ value : 1 element
▿ 0 : 7 elements
▿ 0 : 2 elements
- key : location
- value : 1234 ANY ADDRESS ST ANYTOWN
▿ 1 : 2 elements
- key : agencyId
- value : 3-08
▿ 2 : 2 elements
- key : alarmLevel
- value : 0
▿ 3 : 2 elements
- key : agencyEventSubtypeCode
- value : 59-C-3O
▿ 4 : 2 elements
- key : originatingAction
- value : CadEventNew
▿ 5 : 2 elements
- key : agencyEventId
- value : CC17187712
▿ 6 : 2 elements
- key : dateTime
- value : 2017-12-22T22:37:27Z
Which I believe you'd refer to as a nested dictionary. "value" prints:
▿ 1 element
▿ 0 : 7 elements
▿ 0 : 2 elements
- key : location
- value : 1234 ANY ADDRESS ST ANYTOWN
▿ 1 : 2 elements
- key : agencyId
- value : 3-08
▿ 2 : 2 elements
- key : alarmLevel
- value : 0
▿ 3 : 2 elements
- key : agencyEventSubtypeCode
- value : 59-C-3O
▿ 4 : 2 elements
- key : originatingAction
- value : CadEventNew
▿ 5 : 2 elements
- key : agencyEventId
- value : CC17187712
▿ 6 : 2 elements
- key : dateTime
- value : 2017-12-22T22:37:27Z
I have no idea how to get into the next level or levels to retrieve the value for each key shown. The end goal is to show some or all of the data in a tableview. Like I said, I have no experience. Any help (in the simplest terms) would be greatly appreciated.
Looks like your value is another dictionary. So
if let dict = value as Dictionary {
for key in dict.allKeys {
print("the value for key \(key) is:")
print(dict[key])
}
}
I would like to know (if it's possible) how to add a 0 value ine Leafletjs block's legend.
For an example, this is my class :
function getColorPOPULATION(d) {
return d > 500 ? '#004590' :
d > 250 ? '#00ABFF' :
d > 1 ? '#A0E0FF' :
'#FFF4D0' ;
... and my grades (div legend) :
grades = [0, 1, 250, 500],
-> I get this result :
0 - 1
1 - 250
250 - 500
500+
I would like to isolate the 0 value (my first class will be 0). Does Leafletjs able to do this ?
Thank you,
I have a configuration collection with below fields:
1) Model
2) Threshold
In above collection, certain threshold value is given for every model like as follow:
'model1' 200
'model2' 400
'model3' 600
There is another collection named customer with following fields:
1)model
2)customerID
3)baseValue
In above collection, data is as follow:
'model1' 'BIXPTL098' 300
'model2' 'BIXPTL448' 350
'model3' 'BIXPTL338' 500
Now I need to get the count of customer records which have baseValue for that particular model greater than the threshold of that particular model in configuration collection.
Example : For the above demo data, 1 should be returned by the query as there is only one customer(BIXPTL098) with baseValue(300) greater than Threshold(200) for that particular model(model1) in configuration
There are thousands of records in configuration collection. Any help is appreciated.
How often does the threshold change? If it doesn't change very often, I'd store the difference between the model threshold and the customer baseValue on each document.
{
"model" : "model1",
"customerID" : "BIXPTL098",
"baseValue" : 300,
"delta" : 100 // customer baseValue - model1 threshold = 300 - 200 = 100
{
and query for delta > 0
db.customers.find({ "delta" : { "$gt" : 0 } })
If the threshold changes frequently, the easiest option would be to compute customer documents exceeding their model threshold on a model-by-model basis:
> var mt = db.models.findOne({ "model" : "model1" }).threshold
> db.customers.find({ "model" : "model1", "baseValue" : { "$gt" : mt } })
I'm trying to get the closest data from the following data
> db.points.insert({name:"Skoda" , pos : { lon : 30, lat : 30 } })
> db.points.insert({name:"Honda" , pos : { lon : -10, lat : -20 } })
> db.points.insert({name:"Skode" , pos : { lon : 10, lat : -20 } })
> db.points.insert({name:"Skoda" , pos : { lon : 60, lat : -10 } })
> db.points.insert({name:"Honda" , pos : { lon : 410, lat : 20 } })
> db.points.ensureIndex({ loc : "2d" })
then I tried
> db.points.find({"loc" : {"$within" : {"$centerSphere" : [[0 , 0],5]}}})
this time I got different error
error: {
"$err" : "Spherical MaxDistance > PI. Are you sure you are using radians?",
"code" : 13461
then I tried
> db.points.find({"loc" : {"$within" : {"$centerSphere" : [[10 , 10],2]}}})
error: {
"$err" : "Spherical distance would require wrapping, which isn't implemented yet",
"code" : 13462
How to get this done ? I just want to get the closest data based on the given radious from GEO point.
Thanks
A few things to note. Firstly, you are storing your coordinates in a field called "pos" but you are doing a query (and have created an index) on a field called "loc."
The $centerSphere takes a set of coordinates and a value that is in radians. So $centerSphere: [[10, 10], 2] searches for items around [10, 10] in a circle that is 2 * (earth's radius) = 12,756 km. The $centerSphere operator is not designed to search for documents in this large of an area (and wrapping around the poles of the Earth is tricky). Try using a smaller value, such as .005.
Finally, it is probably a better idea to store coordinates as elements in an array since some drivers may not preserve the order of fields in a document (and swapping latitude and longitude results in drastically different geo locations).
Hope this helps:
The radius of the Earth is approximately 3963.192 miles or 6378.137 kilometers.
For 1 mile:
db.places.find( { loc: { $centerSphere: [ [ -74, 40.74 ] ,
1 / 3963.192 ] } } )