Immutable.js: Is this an expected hashCode collision, or a bug? - immutable.js

So I was playing around with Immutable.js's hashCode function, and I pretty soon found a collision:
Immutable.Map({ hello: 1, world: 2 }).hashCode() === Immutable.Map({ world: 1, hello: 2 }).hashCode() // true
Now the docs clearly state (emphasis mine):
If two values have the same hashCode, they are not guaranteed to be equal.
But I'm just wondering if this "trivial" example is a "valid" collision, or a bug? Or am I missing something super obvious?

Related

BoxClassifierLoss/localization_loss and Loss/regularization_loss also zero using Tensorflow Objectdetection API

I have now been trying to train a object-detection model for some time, namely the "faster_rcnn_resnet152_v1_640x640_coco17_tpu-8" model. However, during this whole training process, neither the BoxClassifierLoss/localization_loss or the Loss/regularization_loss has been higher than zero.
Has anyone else had similar issues, or do anyone know a solution?
(I think this is the reason why my model performs very very poorly atleast)
INFO:tensorflow:{'Loss/BoxClassifierLoss/classification_loss': 0.011540242,
'Loss/BoxClassifierLoss/localization_loss': 0.0,
'Loss/RPNLoss/localization_loss': 0.05603733,
'Loss/RPNLoss/objectness_loss': 0.021345321,
'Loss/regularization_loss': 0.0,
'Loss/total_loss': 0.08892289,
'learning_rate': 0.090500005}
I1105 01:40:26.982768 16300 model_lib_v2.py:705] {'Loss/BoxClassifierLoss/classification_loss': 0.011540242,
'Loss/BoxClassifierLoss/localization_loss': 0.0,
'Loss/RPNLoss/localization_loss': 0.05603733,
'Loss/RPNLoss/objectness_loss': 0.021345321,
'Loss/regularization_loss': 0.0,
'Loss/total_loss': 0.08892289,
'learning_rate': 0.090500005}
'localization_loss' always staying at 0.0 can be due to an error in your tfrecords-file, or, most likely an error in your label_map. Check if your label_map matches with the classes in your tfrecords-file and is correctly formatted.
When your localization and regularization loss is zero, it means there is some problem with generating tfrecords files. When creating annotations for image files your labels should be consistent with you label map file.
Extract from example tf record
feature {
key: "image/object/class/text"
value {
bytes_list {
value: "paragraph"
value: "paragraph"
value: "table"
value: "paragraph"
}
}
}
Now when you create labelmap.pbtxt it should exactly match with above values
Extract from sample labelmap file
item {
name: "paragraph"
id: 1
}
item {
name: "table"
id: 2
}
After making this change you localization_loss should not be zero anymore.

DC.JS How to handle objects with different amount of properties

Let's say i have 2 objects each with the same properties but one has an extra property middleName and the other does not.
How should i handle this in DC.js?
var objects = [{
name: "De Smet",
firstName: "Jasper",
adress: "Borsbeke",
},{
name: "De Backer",
firstName: "Dieter",
middleName: "middleName",
adress: "Borsbeke"
},{
name: "De Bondtr",
firstName: "Simon",
middleName: "OtherMiddleName",
adress: "Denderleeuw"
}
]
The wanted behaviour would be that the object without the property gets filtered out. Like so:
Here is a fiddle:
https://jsfiddle.net/mj92shru/41/
It seems to add the property middlename to the first object and assigns it the next middlename it finds
Adding the property to the first object and adding a placeholder value like "none" works but it doesnt really produce wanted behaviour.
I realize i could filter out the objects where the middlename is set to "none" but this would be difficult in the actual application i am writing
i've also found that adding the object without the property last causes it to crash.
Indeed, using undefined fields for your dimension or group keys can crash crossfilter because it does not validate its data. NaN, null, and undefined do not have well-defined sorting operations.
It's strange to see the value folded into another bin, but I suspect it's the same undefined behavior, rather than something you can depend on.
If you have fields which may be undefined, you should always default them, even if you don't want the value:
middleNameDimension = j.dimension(d => d.middleName || 'foo'),
I think you do want to filter your data, but not in the crossfilter sense where those rows are removed and do not influence other charts. Instead, it should just be removed from the group without affecting anything else.
You can use a "fake group" for this, and there is one in the FAQ which is suited perfectly for your problem:
function remove_bins(source_group) { // (source_group, bins...}
var bins = Array.prototype.slice.call(arguments, 1);
return {
all:function () {
return source_group.all().filter(function(d) {
return bins.indexOf(d.key) === -1;
});
}
};
}
Apply it like this:
.group(remove_bins(middleNameGroup, 'foo'))
Fork of your fiddle.
Be careful with this, because a pie chart implicitly adds up to 100%, and in this case it only adds up to 66%. This may be confusing for users, depending how it is used.

Best way to compare values to two javascript objects

I am writing a bunch of unit tests and was wondering what is the best way to compare values of two javascript objects (the actual vs the expected). Lets say I have the following
ActualObject: {
Val1: '1',
Val2: '2',
Val3: '3',
Val4: '4'
}
ExpectedObject: {
Val1: '1',
Val2: '2',
Val3: '3',
Val4: '4'
}
Now I want to check if the values of the properties in each of the objects are equal. What is the best way to do this. Currently I am comparing all the properties individually. The alternative I can think of is JSON.stringify, however I'm not sure if this will change the order of the properties at random?
There isn't really a simple "one answer fits all" solution to this, especially as the parameters of your question are quite broad. For example, what would you consider equality? Strict? Loose? Equality of only own enumerable properties, or of all properties?
I would recommend steering clear of using JSON.stringify as 1) it is a fairly costly operation to serialise an object, especially if performing frequently, and 2) it transforms values in potentially dangerous ways for comparison sake (e.g. JSON.stringify(NaN) === JSON.stringify(null) //=> true).
You should use a library implementation such as lodash's isEqual, and save yourself the pain of reinventing the wheel.
However for the sake of completeness, and to give you an idea of a simple, naive approach, you could loop over each property of your object ExpectedObject and check for equality with the equivalent property in the object ActualObject, like so:
function isEqual (ExpectedObject, ActualObject) {
// if the ExpectedObject has a different number of
// keys than ActualObje, it is not equal
if (Object.keys(ExpectedObject).length !== Object.keys(ActualObject).length) {
return false
}
for (const key in ExpectedObject) {
// if ActualObject does not have a property that is
// on ExpectedObject, it is not equal
if (!(key in ActualObject)) {
return false
}
// if a property's value on ActualObject is not equal
// with a strict comparison, to the equivalent property
// on ExpectedObject, it is not equal
if (ActualObject[key] !== ExpectedObject[key]) {
return false
}
}
return true
}
console.log(isEqual({ a:1 }, { a: 1 })) //=> true
console.log(isEqual({ a:1 }, { a: "1" })) //=> false
console.log(isEqual({ a:1 }, { a: 1, b: 2 })) //=> false
Obviously you would need to introduce type-checking so that you know you're dealing with objects to begin with, but there's a basic idea for you to think about.

ImmutableJs - compare objects but for one property

I am converting a shopping basket to an immutable structure.
Is there an easy way with immutablejs to see if an immutable object already exists within an immutable list EXCEPT for one object property 'quantity' which could be different? List example:
[{
id: 1,
name: 'fish and chips',
modifiers: [
{
id: 'mod1',
name: 'Extra chips'
}
],
quantity: 2
},{
id: 2,
name: 'burger and chips',
modifiers: [
{
id: 'mod1',
name: 'No salad'
}
],
quantity: 1
}]
Now, say I had another object to put in the list. But I want to check if this exact item with modifiers exists in the list already? I could just do list.findIndex(item => item === newItem) but because of the possible different quantity property then it wont work. Is there a way to === check apart from one property? Or any way to do this without having to loop through every property (aside from quantity) to see if they are the same?
Currently, I have an awful nested loop to go through every item and check every property to see if it is the same.
Well this should work-
list.findIndex(item => item.delete("quantity").equals(newItem.delete("quantity"))
The equals method does deep value comparison. So once you delete the quantity, you are comparing all values that matter.
PS: please ignore code formatting, I am on SO app.
PPS: the above code is not optimal, you should compare a pre-trimmed newItem inside the arrow function instead of trimming it there.

I can't manage to create 3rd level of dijit.Tree

I wanted to create a 3 level dijit.Tree, like that:
-root
|
--level1
|
--level2
I thought it would be really simple since there's a code snippet in this tutorial (example 1). But somehow I manage to fail.
This is my dojo code (variable names are in Polish, I hope it's not a problem):
modelRaportow = new dijit.tree.ForestStoreModel({
store: new dojo.data.ItemFileReadStore({
url: "logika/getJSON/getStatusRaportow.php"
}),
query: {typ: 'galaz'},
rootId: 'statusRaportuRoot',
rootLabel: 'Status raportu',
childrenAttrs: 'raporty'
});
drzewoRaportow = new dijit.Tree({
openOnClick: true,
model: modelRaportow,
showRoot: true,
persist: false
}, "target-status-raportow");
drzewoRaportow.startup();
This is my JSON returned by logika/getJSON/getStatusRaportow.php (again, names are in Polish):
{
"identifier":"id",
"label":"status",
"items": [
{"id":0,"status":"zaakceptowane","typ":"galaz"
"raporty":[{"_reference":1},{"_reference":2},{"_reference":3}]},
{"id":1,"data":"24-10-2011","wykonujacy":"cblajszczak","idKlienta":3,"status":"Raport0","typ":"lisc"},
{"id":2,"data":"24-10-2011","wykonujacy":"cblajszczak","idKlienta":1,"status":"Raport1","typ":"lisc"},
{"id":3,"data":"24-10-2011","wykonujacy":"cblajszczak","idKlienta":3,"status":"Raport2","typ":"lisc"},
{"id":4,"status":"odrzucone","typ":"galaz"
"raporty":[{"_reference":5},{"_reference":6},{"_reference":7}]},
{"id":5,"data":"24-10-2011","wykonujacy":"cblajszczak","idKlienta":1,"status":"Raport3","typ":"lisc"},
{"id":6,"data":"24-10-2011","wykonujacy":"cblajszczak","idKlienta":3,"status":"Raport4","typ":"lisc"},
{"id":7,"data":"24-10-2011","wykonujacy":"cblajszczak","idKlienta":3,"status":"Raport5","typ":"lisc"}
]}
And finally, this is what I'm getting: img - root node and lvl 1 nodes returned by query, no child nodes.
The question is - where is my mistake? Can anyone see it?
You have no comma between the typ and raporty value pair.
I have a partial answer: by stepping through the code in a similar situation, I've discovered that it expects childrenAttrs to be an array, so it should be:
childrenAttrs: ['raporty']
but I still cannot get the third level to appear in my case.