How to add lines between individual data points? - highcharts

I'm trying to make a scatter plot in Highcharts that only connects two individual points to each other, but doesn't connect to any other points. (To show the change in a data point over time).
Here I illustrate my question. I'd like for there to be a line between the points
[20, 20] and [80, 80]
and a separate line connecting
[60, 40] to [85, 60]
but no line connecting
[80, 80] to [60, 40]
Is there an easily configurable way to do this, or do I have to manually render each line?

You can simple add null between these points.
data: [[20, 20], [80, 80], null, [60, 40], [85, 60]]
Demo

Related

highchartr: Synchronize point and line colors and legend

I'm using the highchartr package to create an interactive chart.
My chart has lines on it corresponding to different series. In addition, I would like to have shapes at certain points on the lines.
Its very easy to get the points in the right place. However, I would like to map the point color to the line it is associated with. And when the user clicks on the legend entry for the line, I'd like the associated points to be toggled as well.
The code looks like this:
highchart() %>%
hc_add_series(
type="line",
marker=list(enabled=F),
data=input_data,
mapping=hcaes(x=x, y=y, group=series_name)
) %>%
hc_add_series(
type="point",
data=input_data %>% filter(! is.na(marker)),
mapping=hcaes(x=x, y=y, color=series_name, fill=series_name, group=series_name, shape=marker)
)
The result gets the points in the right place. But the point color is on a different color mapping from the lines. Clicking on the entry for the line in the legend toggles only the line - the points show up as separate entries by series_name.
What
What can I do so:
- The points and lines share the same color mapping
- The points and lines can be toggled together by clicking on the line in the legend
- The points show up separately in the legend based on their shape rather than their color?
Thanks!
Generally, it can be achieved in at least few different ways. It all depends on your data which you haven't provided (I created a sample data).
Additionally, I will provide all the examples in jsFiddle (JavaScript) because it is faster to explain something that way with a quick online example.
The final answer will contain R code (maybe with some custom JavaScript if needed, but all will be reproducible in R.
First of all, your assumption that you need a separate series is wrong and causes problems. If you want markers on your line with the same color and you want to toggle them together on legend click, then you don't need separate series - one series with markers enabled on some points is enough, see this example: https://jsfiddle.net/BlackLabel/s24rk9x7/
In this case, the R data needs to be defined properly.
If you don't want to keep it simple as described above, you can keep lines and markers as separate series as in your original question.
In this case, you can use series.linkedTo property to connect your "point" series to line series (BTW in Highcharts there is no something like "point" series type, it is "scatter" series type. Another reason why your code is wrong and is not working and you got unvoted), but there is a problem with it in Highcharter - doesn't work, seems like a bug and should be reported on Highcharter GitHub repo.
This is a JavaScript version which works fine: https://jsfiddle.net/BlackLabel/3mtdfqLo/
In this example, if you want to keep markers and line series in the same color, you can define colors manually or you can write some custom code (like I did) that will change the color for you automatically.
And this is the same R version which should work, but is not:
library(highcharter)
highchart() %>%
hc_add_series(
data=list(4, 3, 5, 6, 2, 3)
) %>%
hc_add_series(
data=list(14, 13, 15, 16, 12, 13),
id="first"
) %>%
hc_add_series(
data=list(10, 8, 6, 2, 5, 12),
id="second"
) %>%
hc_add_series(
type="scatter",
linkedTo="first",
data=list(list(1, 3), list(2, 5))
) %>%
hc_add_series(
type="scatter",
linkedTo="second",
data=list(list(1, 13), list(2, 15), list(3, 16))
) %>%
hc_plotOptions(
line = list(marker=list(enabled=F))
)
There is probably something wrong with hc_add_series function.
As a workaround, you can write it all as a custom JavaScript code, which (again) works fine:
library(highcharter)
highchart() %>%
hc_plotOptions(
line = list(marker=list(enabled=F))
) %>%
hc_chart(
events = list(load = JS("function() {
this.addSeries({
data: [4, 3, 5, 6, 2, 3],
id: 'first'
});
this.addSeries({
data: [14, 13, 15, 16, 12, 13],
id: 'second'
});
this.addSeries({
data: [10, 8, 6, 2, 5, 12]
});
this.addSeries({
type: 'scatter',
linkedTo: 'first',
data: [[1, 3], [2, 5]]
});
this.addSeries({
type: 'scatter',
linkedTo: 'second',
data: [[1, 13], [2, 15], [3, 16]]
});
}")))
Of course, last examples don't contain functionality that changes colors - you can copy it from the jsFiddle above.

Same vs Different Target Values for each sample for Regression in Machine Learning

I am a newbie in machine learning and learning the basic concepts in regression. The confusion I have can be well explained by placing an example of input samples with the target values. So, For example (please notice that the example I am putting is the general case, I observed the performance and predicted values on a large custom dataset of images. Also, notice that the target values are not in floats.), I have:
xtrain = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
ytrain = [10, 10, 10, 20, 20, 20, 30, 30, 30, 40, 40, 40]
and
xtest = [13, 14, 15, 16]
ytest = [25, 25, 35, 35]
As you can notice that the ever three (two in the test set) samples have similar target values. Suppose I have a multi-layer perceptron network with one Flatten() and two Dense() layers. The network, after training, predicts the target values all same for test samples:
yPredicted = [40, 40, 40, 40]
Because the predicted values are all same, the correlations between ytest and yPredicted return null and give an error.
But when I have:
xtrain = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
ytrain = [332, 433, 456, 675, 234, 879, 242, 634, 789, 432, 897, 982]
And:
xtest = [13, 14, 15, 16]
ytest = [985, 341, 354, 326]
The predicted values are:
yPredicted = [987, 345, 435, 232]
which gives very good correlations.
My question is, what it the thing or process in a machine learning algorithm that makes the learning better when having different target values for each input? Why the network does not work when having repeated values for a large number of inputs?
Why the network does not work when having repeated values for a large number of inputs?
Most certainly, this is not the reason why your network does not perform well in the first dataset shown.
(You have not provided any code, so inevitably this will be a qualitative answer)
Looking closely at your first dataset:
xtrain = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
ytrain = [10, 10, 10, 20, 20, 20, 30, 30, 30, 40, 40, 40]
it's not difficult to conclude that we have a monotonic (increasing) function y(x) (it is not strictly monotonic, but it is monotonic nevertheless over the whole x range provided).
Given that, your model has absolutely no way of "knowing" that, for x > 12, the qualitative nature of the function changes significantly (and rather abruptly), as apparent from your test set:
xtest = [13, 14, 15, 16]
ytest = [25, 25, 35, 35]
and you should not expect it to know or "guess" it in any way (despite what many people may seem to believe, NN are not magic).
Looking closely to your second dataset, you will realize that this is not the case with it, hence the network is unsurprisingly able to perform better here; when doing such experiments, it is very important to be sure that we are comparing apples to apples, and not apples to oranges.
Another general issue with your attempts here and your question is the following: neural nets are not good at extrapolation, i.e. predicting such numerical functions outside the numeric domain on which they have been trained. For details, please see own answer at Is deep learning bad at fitting simple non linear functions outside training scope?
A last unusual thing here is your use of correlation; not sure why you choose to do this, but you may be interested to know that, in practice, we never assess model performance using a correlation measure between predicted outcomes and ground truth - we use measures such as the mean squared error (MSE) instead (for regression problems, such as yours here).

Splitting complex PDF files using Watson Document Conversion Service

We are implementing Question & Answering System using Watson Discovery Service(WDS). We required each answer unit available in single document. We have complex PDF files as corpus. The PDF files contains two column data, tables and images. Instead ingesting whole PDF files as corpus to WDS and using passage retrieval we are using Watson Document Conversion Service(WDC) to split each PDF file into answer units and later we are ingesting there answer units into WDS.
We are facing two issues with Watson Document Conversion service for complex PDF splitting.
We are expecting each heading as title and corresponding text as data(answer). However it is splitting each chapter as single answer unit. Is there any way to split the two column document based on the heading?
In case the input PDF file contains table the document conversion service reading structured data available in PDF file as simple text(missing table formatting). Is there any way to read structured data from PDF to answer unit?
I would recommend that you first convert your PDF to normalized HTML by using this setting:
"conversion_target": "normalized_html"
and inspect the generated HTML. Look for the places where headings (<h1>, <h2>, ..., <h6>) are detected. Those are the tags that will be used to split by answer units when you switch back to answer_units.
The reason you are currently seeing each chapter being split as an answer unit is because each chapter probably starts with a heading, but no headings are detected within each chapter.
In order to generate more answer units, you will need to tweak the PDF input configurations as described here, so that more headings are generated from the PDF to HTML conversion step and hence more answer units are generated.
For example, the following configuration will detect headings at 6 different levels, based on certain font characteristics for each level:
{
"conversion_target": "normalized_html",
"pdf": {
"heading": {
"fonts": [
{"level": 1, "min_size": 24},
{"level": 2, "min_size": 18, "max_size": 23, "bold": true},
{"level": 3, "min_size": 14, "max_size": 17, "italic": false},
{"level": 4, "min_size": 12, "max_size": 13, "name": "Times New Roman"},
{"level": 5, "min_size": 10, "max_size": 12, "bold": true},
{"level": 6, "min_size": 9, "max_size": 10, "bold": true}
]
}
}
}
You can start with a configuration like this and keep tweaking it until the produced normalized HTML contains the headings at the places that you expect the answer units to be. Then, take the tweaked configuration, switch to answer_units and put it all together:
{
"conversion_target": "answer_units",
"answer_units": {
"selector_tags": ["h1", "h2", "h3", "h4", "h5", "h6"]
},
"pdf": {
"heading": {
"fonts": [
{"level": 1, "min_size": 24},
{"level": 2, "min_size": 18, "max_size": 23, "bold": true},
{"level": 3, "min_size": 14, "max_size": 17, "italic": false},
{"level": 4, "min_size": 12, "max_size": 13, "name": "Times New Roman"},
{"level": 5, "min_size": 10, "max_size": 12, "bold": true},
{"level": 6, "min_size": 9, "max_size": 10, "bold": true}
]
}
}
}
Regarding your second question about tables, unfortunately there is no way to convert table content into answer units. As explained above, answer unit generation is based on heading detection. That being said, if there is a table between two detected headings, that table will be part of the answer unit as any other content between the two headings.

Highcharts: Disconnect line when there's no data for position

in my project I'm using highcharts/stockcharts. See my JS-fiddle example for a simple graph with X-axis 1 to 10, but no data for "position 9". I want no line to be drawn between 8 and 10, since there is no data for 9.
I've been playing with the connectNulls option, but that only works when providing null as value for position 9. Since Highcharts figures out the intervals by itself I hoped it would recognise on its own that there's no data for that position. Is there any way to make Highcharts not draw a line between 8 and 10 without specifying null for position 9?
Thanks in advance for your replies.
http://jsfiddle.net/bnqhuqt3/
You can not cut a line in a serie. You need to define a new data for series
series: [{
data: [
[1, 98.87],
[2, 98.45],
[3, 98.52],
[4, 99.34],
[5, 98.56],
[6, 98.61],
[7, 98.12],
[8, 98.03],
]
}, {
data: [
[10, 0],
[11, 150]
]
}]
Fiddle Example

Is there a way to parse multiple co-ordinates script data incorrectly set wrong by 180 degrees in LSL (Linden Scripting Language)?

I am using LSL (Linden Scripting Language) in Second Life. I have imported a virtual (mesh) aircraft object and spent hours animating various parts such as canopy and undercarriage.
I have now discovered that I should have imported the object to face east when all axis are set to zero (mine was facing west). I have now re-imported the object with the correct orientation, however as the main mesh object was my 'root prim' and the frames storing the positions of every animated part was relative to that, all the animated parts (child prims) are now reversed by exactly 180 degrees.
Does anyone know of a way I could parse the script data to find and automatically add a correction of 180 degrees?
I spent hours on the animations and have pages of data, so an automated solution would be extremely preferable and any help gratefully received.
A snippet of the code I need to parse is reproduced below:
link_message(integer n, integer c, string m, key id){
vector lSize = llList2Vector(llGetLinkPrimitiveParams(1,[7]),0);
if(m == lAnimName + "|0"){// Frame 0.
if(lLeg3t)
llSetLinkPrimitiveParamsFast(lLeg3t,[
33, <0.245628*lSize.x, -0.183868*lSize.y, -0.184195*lSize.z>, 29, <-0.500000, 0.000000, -0.707107, 0.500000>
]);
if(lWire3t)
llSetLinkPrimitiveParamsFast(lWire3t,[
33, <0.259854*lSize.x, -0.187642*lSize.y, -0.196354*lSize.z>, 29, <-0.500000, 0.000000, -0.707107, 0.500000>
]);
if(lWire3b)
llSetLinkPrimitiveParamsFast(lWire3b,[
33, <0.244813*lSize.x, -0.194661*lSize.y, -0.171052*lSize.z>, 29, <0.073912, -0.549525, -0.444997, 0.703233>
]);
if(lFoot3)
llSetLinkPrimitiveParamsFast(lFoot3,[
33, <0.261851*lSize.x, -0.180508*lSize.y, -0.157508*lSize.z>, 29, <-0.270598, -0.270598, -0.653282, 0.653282>
]);
if(lLeg3b)
llSetLinkPrimitiveParamsFast(lLeg3b,[
33, <0.247470*lSize.x, -0.200321*lSize.y, -0.190136*lSize.z>, 29, <0.073912, -0.549525, -0.444997, 0.703233>
]);
if(lSled3)
llSetLinkPrimitiveParamsFast(lSled3,[
33, <0.251954*lSize.x, -0.184123*lSize.y, -0.169543*lSize.z>, 29, <0.000000, 0.000000, -0.707107, 0.707107>
]);
if(lWire2t)
llSetLinkPrimitiveParamsFast(lWire2t,[
33, <0.268535*lSize.x, 0.190722*lSize.y, -0.196969*lSize.z>, 29, <-0.061628, 0.541675, -0.454520, 0.704416>
]);
if(lLeg2t)
llSetLinkPrimitiveParamsFast(lLeg2t,[
33, <0.255244*lSize.x, 0.185132*lSize.y, -0.176223*lSize.z>, 29, <-0.061628, 0.541675, -0.454520, 0.704416>
]);
if(lWire2b)
llSetLinkPrimitiveParamsFast(lWire2b,[
33, <0.237334*lSize.x, 0.180499*lSize.y, -0.159385*lSize.z>, 29, <0.517145, -0.024678, -0.706676, 0.482246>
]);
I'm no scripter but, I think I kinda get what's going on....
Try this - import your vehicle in Blender. Select all the parts, making sure your vehicle is facing the correct direction. If it's not, hit R, then Z, then the number of the degrees you want it to rotate, then Enter.
Once the vehicle is facing the correct direction. Hit Ctrl-A and select 'Rotation' in the pop up menu. This resets the rotation data all to 0. Export your object and upload it. You'll find when you rezz it that the rotation of all the parts are now set to 0.
If I understand your quandry correctly that should resolve the rotation issue of the child prims?
If not...see what happens when scripting noobs try to be helpful? =/
My recollection is if you flip the sign on any single non-zero quaternion component it will flip the rotation 180 degrees.
So...
if(lLeg3b)
llSetLinkPrimitiveParamsFast(lLeg3b,[
33, <0.247470*lSize.x, -0.200321*lSize.y, -0.190136*lSize.z>, 29, <0.073912, -0.549525, -0.444997, 0.703233>
]);
becomes:
if(lLeg3b)
llSetLinkPrimitiveParamsFast(lLeg3b,[
33, <0.247470*lSize.x, -0.200321*lSize.y, -0.190136*lSize.z>, 29, <-0.073912, -0.549525, -0.444997, 0.703233>
]);

Resources