I am trying to draw a boxplot using zingchart. I need a legend for the chart, but the legend generated is wrong. is it a bug in zingchart?
Below is the json passed in:
{
"type": "boxplot",
"vertical-labels": true,
"legend":{},
"scale-x": {
"labels": []
},
"series": [
{
"data-box": [ [760, 801, 848, 895, 965 ],[733, 853, 939, 980, 1080 ]],
"text":"f1"
},
{
"data-box": [[733, 853, 939, 980, 1080 ],[733, 853, 939, 980, 1080 ]],
"text":"f2"
}
]
}
And this is the genrated boxplot, which should have two series, but it generated four series.
Is it a bug or I passed the wrong json data? Thanks in advance.
sinsin.
Sorry to see that you're having an issue with our boxplot module. However, this is an issue with the boxplot module itself, and not anything you did! I'm on the ZingChart support team, so I'll be sure to pass this on to our developers. In the meantime, you can create your own legend using shapes with labels on those shapes, as I've done here.
I'm a big fan of boxplot charts, but this is a relatively new ZingChart module, and it looks like it needs some more love.
Related
Hi there potential helpers, I've been following this guide https://blog.tensorflow.org/2021/11/3D-handpose.html
I seem to have everything setup vaguely correctly
But detector.estimateHands(video) is returning an object with NaN as the score and every coordinate:
[{
handedness: "Right",
score: NaN,
keypoints: [
{x: NaN, y: NaN, name: 'wrist'},
{x: NaN, y: NaN, name: 'thumb_cmc'},
etc...
],
keypoints3d: [
{x: NaN, y: NaN, z: NaN, name: 'wrist'},
etc...
]
}]
The thing that makes me think it's almost working is that it only returns that object if I actually have my hand in front of the webcam. And if I hold two hands up it returns two of these objects. And then if I hide my hands it returns an empty array.
So it is recognising hands, it's just not returning any usable scores.
Here is the essence of the code:
const model = handPose.SupportedModels.MediaPipeHands;
const config = {
modelType:"full",
runtime: "tfjs"
};
const detector = await handPose.createDetector(model, config);
and then in an requestAnimationFrame loop:
const video = shadowRoot.querySelector('video');
const hands = await detector.estimateHands(video);
console.log(hands);
console.log(hands[0]?.score);
I've got all the mentioned npm modules installed
#tensorflow/tfjs
#tensorflow-models/hand-pose-detection
#tensorflow/tfjs-core
#tensorflow/tfjs-converter
#tensorflow/tfjs-backend-webgl
And I've tried playing with config that can be passed into createDetector and estimateHands but with the typescript definitions there's not much choice.
Anyone seen this before and have any idea how to fix it?
Thank you 🙇
How do I best use data objects for React Google Charts so I can access more information than just the 2 co-ordinates values.
Example:
https://codesandbox.io/s/react-google-charts-trendline-k727v9
The data object is just an array with x/y values: price and mileage.
export const data = [
["mileage", "price", { role: "style" }],
[5000, 12700, "green"],
[10000, 11200, "red"],
[15000, 9800, "red"],
[20000, 9200, "green"],
[25000, 8000, "red"],
[30000, 7200, "green"],
[35000, 5400, "green"]
];
The real object I would like to use would have the same x/y values, but a number of more key/value pairs, e.g.:
export const data = [
["mileage", "price", 'status', 'url', 'age'],
[5000, 12700, 'sold', 'sth.com', 13],
[10000, 11200, 'sold', 'sth.com', 13],
[15000, 9800, 'sold', 'sth.com', 13],
[20000, 9200, 'sold', 'sth.com', 13],
[25000, 8000, 'sold', 'sth.com', 13],
[30000, 7200, 'sold', 'sth.com', 13],
[35000, 5400, 'sold', 'sth.com', 13]
];
First of all sth. likle this throws an error because the values are not all of the same type, numbers and strings in this case.
Secondly I would like to be able to access these additional values in my chart event function. E.g. Click on a node and not only access price and mileage but also display all the other data associated with this node.
Obviously I could filter my original data array, split it into two, then fit the pieces back together again when I need a bit of data. But is that really the way to go?
I have use Nivo Charts before. There you could have complex objects and simply define which keys should be used to paint the nodes and still access all other keys/values associated with a data object. So I would use "mileage" and "price to paint the dots" but still have all the other key/values accessible as part of the data object for anything else I may want to do with it. I have not been able to figure out how to do sth. similar with React Google Charts.
Also d3-shape allows you to draw a line specifying 2 key/value pairs as the coordinates from a data object that can have any number of key/value pairs, not just x/y, e.g.:
const lineGenerator = line()
.x((d) => xScale(d.data.myField))
.y((d) => yScale(d.data.myOtherField))
Thank you!
I've been using GEE to export some training patches from Sentinel-2 to be used in Python.
I could make it work, by following the GEE guide https://developers.google.com/earth-engine/tfrecord, and using the Export.image.toDrive function and then I can parse the exported TFRecord file to reconstruct my tiles.
var image_export_options = {
'patchDimensions': [366, 366],
'maxFileSize': 104857600,
// 'kernelSize': [366, 366],
'compressed': true
}
Export.image.toDrive({
image: clipped_img.select(bands.concat(['classes'])),
description: 'PatchesExport',
fileNamePrefix: 'Oros_1',
scale: 10,
folder: 'myExportFolder',
fileFormat: 'TFRecord',
region: export_area,
formatOptions: image_export_options,
})
However, when I try to specify the kernelSize in the formatOptions (that was supposed to "overlaps adjacent tiles by [kernelSize[0]/2, kernelSize[1]/2]", according to the guide) the files are exported but the '*mixer.json' doesn't reflect the increased number of patches and I am not able to iterate through the patches afterwards. The following command crashes the google colab session:
image_dataset = tf.data.TFRecordDataset(str(path/(file_prefix+'-00000.tfrecord.gz')), compression_type='GZIP')
first = next(iter(image_dataset))
first
The weird is that the problem happens only when I add the kernelSize to the formatOptions.
After some time trying to overcome this issue, I realized a not well documented behavior when one uses the kernel size to export patches from GEE.
Bundled with the exported TFRecord, there exists one xml file called mixer.
It doesn't matter if we use:
'patchDimensions': [184, 184],
'kernelSize': [1, 1], #default for no overlapping
or
'patchDimensions': [184, 184],
'kernelSize': [184, 184], #half patch overlapping
The mixer file remains the same and no mention to the kernel/overlapping size:
{'patchDimensions': [184, 184],
'patchesPerRow': 8,
'projection': {'affine': {'doubleMatrix': [10.0,
0.0,
493460.0,
0.0,
-10.0,
9313540.0]},
'crs': 'EPSG:32724'},
'totalPatches': 40}
In the second case, if we try to parse the patches using tf.io.parse_single_example(example_proto, image_features_dict), where image_features_dict equals something like:
{'B2': FixedLenFeature(shape=[184, 184], dtype=tf.float32, default_value=None),
'B3': FixedLenFeature(shape=[184, 184], dtype=tf.float32, default_value=None),
'B4': FixedLenFeature(shape=[184, 184], dtype=tf.float32, default_value=None)}
it will raise the error:
_FallbackException: This function does not handle the case of the path where all inputs are not already EagerTensors.
Can't parse serialized Example. [Op:ParseExampleV2]
Instead, to parse these records which have kernelSize > 1, we have to consider patchDimentions + kernelSize as the resulting patch size, even though the mixer.xml file says on contraty. In this example, our patchSize would be 368 (original patch size + kernelSize). Be aware that for odd kernel sizes, the number to be added to the original patch size is kernelSize - 1.
I'm trying to make a chart like with c3.js.
For the bubble size I create an array for each "continent" holding the population as a factor to increase the bubble size. Also the country name is stored in the same manner.
When adding the data points to the chart as well as when adding the bubble sizes/country names to the array, the indices are the same. E.g. col_2[0] in the bubbleInfo array is "China". Also in the data columns col_2[0] and col_2_x[0] are 76 and 12000 which are the values for China.
However, in the section where I dynamically get the bubble radius/country name, the index I get from the function parameter is not the one of the col_2 arrays. Instead I get the index in the order in which the dots are spead along the x-Axis.
E.g. I add for x-Axis China (12000), India(5800), Indonesia(9000) in this order.
I'd expect to get index 1 for India, but I get index 0, because 5800 is the lowest of the x values.
Because of that I cannot properly map the indices on the bubble sizes/country names, since the indices are wrong.
Is this a bug and if so, how can I properly map the bubble sizes/country names then?
Here is the JSFiddle:
var chart_3_bubbleSize = {
"col_2": [10.0, 9.0, 3.9, 2.5, ],
"col_1": [3.0, 2.5, ],
"col_3": [2.5, 5.5, ],
};
...
var chart_3_bubbleInfo = {
"col_2": ["China", "India", "Indonesia", "Japan", ],
"col_1": ["Russia", "Germany", ],
"col_3": ["Mexico", "USA", ],
};
...
columns: [
['col_2', 76, 66, 71, 86],
['col_2_x', 12000, 5800, 9000, 36000],
['col_1', 72, 80.4],
['col_1_x', 25000, 40000],
['col_3', 76, 78],
['col_3_x', 16000, 50000],
],
...
point:
{
r: function(d)
{
/*d.index gives the index according to the order along the x-axis, which leads to wrong result, when trying to map to country names/bubble sizes*/
return 2 * chart_3_bubbleSize[d.id][d.index];
}
},
https://jsfiddle.net/51oLxqyt/1/
The first green bubble in the lower left corner should be India, but it has the label "China" and the bubble size of China, because China is at index 0 in the bubbleInfo and bubbleSize arrays.
There is an not documented attribute data.xSort = false, which keeps the original index, which makes it possible to map more dimension e.g. for scatter charts.
More info here: https://github.com/c3js/c3/issues/547#issuecomment-56292971
Using the commits from breznak for the encoders (I wasn't able to figure out "git checkout ..." with GitHub, so I just carefully copied over the three files - base.py, multi.py, and multi_test.py).
I ran multi_test.py without any problems.
Then I adjusted my model parameters (MODEL_PARAMS), so that the encoders portion of 'sensorParams' looks like this:
'encoders': {
'frequency': {
'fieldname': u'frequency',
'type': 'SimpleVector',
'length': 5,
'minVal': 0,
'maxVal': 210
}
},
I also adjusted the modelInput portion of my code, so it looked like this:
model = ModelFactory.create(model_params.MODEL_PARAMS)
model.enableInference({'predictedField': 'frequency'})
y = [1,2,3,4,5]
modelInput = {"frequency": y}
result = model.run(modelInput)
But I get the final error, regardless if I instantiate 'y' as a list or a numpy.ndarray
File "nta/eng/lib/python2.7/site-packages/nupic/encoders/base.py", line 183, in _getInputValue
return getattr(obj, fieldname)
AttributeError: 'list' object has no attribute 'idx0'
I also tried initializing a SimpleVector encoder inline with my modelInput, directly encoding my array, then passing it through modelInput. That violated the input parameters of my SimpleVector, because I was now double encoding. So I removed the encoders portion of my model parameters dictionary. That caused a spit up, because some part of my model was looking for that portion of the dictionary.
Any suggestions on what I should do next?
Edit: Here're the files I'm using with the OPF.
sendAnArray.py
import numpy
from nupic.frameworks.opf.modelfactory import ModelFactory
import model_params
class sendAnArray():
def __init__(self):
self.model = ModelFactory.create(model_params.MODEL_PARAMS)
self.model.enableInference({'predictedField': 'frequency'})
for i in range(100):
self.run()
def run(self):
y = [1,2,3,4,5]
modelInput = {"frequency": y}
result = self.model.run(modelInput)
anomalyScore = result.inferences['anomalyScore']
print y, anomalyScore
sAA = sendAnArray()
model_params.py
MODEL_PARAMS = {
'model': "CLA",
'version': 1,
'predictAheadTime': None,
'modelParams': {
'inferenceType': 'TemporalAnomaly',
'sensorParams': {
'verbosity' : 0,
'encoders': {
'frequency': {
'fieldname': u'frequency',
'type': 'SimpleVector',
'length': 5,
'minVal': 0,
'maxVal': 210
}
},
'sensorAutoReset' : None,
},
'spEnable': True,
'spParams': {
'spVerbosity' : 0,
'globalInhibition': 1,
'columnCount': 2048,
'inputWidth': 5,
'numActivePerInhArea': 60,
'seed': 1956,
'coincInputPoolPct': 0.5,
'synPermConnected': 0.1,
'synPermActiveInc': 0.1,
'synPermInactiveDec': 0.01,
},
'tpEnable' : True,
'tpParams': {
'verbosity': 0,
'columnCount': 2048,
'cellsPerColumn': 32,
'inputWidth': 2048,
'seed': 1960,
'temporalImp': 'cpp',
'newSynapseCount': 20,
'maxSynapsesPerSegment': 32,
'maxSegmentsPerCell': 128,
'initialPerm': 0.21,
'permanenceInc': 0.1,
'permanenceDec' : 0.1,
'globalDecay': 0.0,
'maxAge': 0,
'minThreshold': 12,
'activationThreshold': 16,
'outputType': 'normal',
'pamLength': 1,
},
'clParams': {
'regionName' : 'CLAClassifierRegion',
'clVerbosity' : 0,
'alpha': 0.0001,
'steps': '5',
},
'anomalyParams': {
u'anomalyCacheRecords': None,
u'autoDetectThreshold': None,
u'autoDetectWaitRecords': 2184
},
'trainSPNetOnlyIfRequested': False,
},
}
The problem seems to be that the SimpleVector class is accepting an array instead of a dict as its input, and then reconstructs that internally as {'list': {'idx0': 1, 'idx1': 2, ...}} (ie as if this dict had been the input). This is fine if it is done consistently, but your error shows that it's broken down somewhere. Have a word with #breznak about this.
Working through the OPF was difficult. I wanted to input an array of indices into the temporal pooler, so I opted to interface directly with the algorithms (I relied heavy on hello_tp.py). I ignored SimpleVector all together, and instead worked through the BitmapArray encoder.
Subutai has a useful email on the nupic-discuss listserve, where he breaks down the three main areas of the NuPIC API: algorithms, networks/regions, & the OPF. That helped me understand my options better.