Different Data Lines on Kendo UI Graphs - user-interface

I have a Kendo UI line chart.
This has x axis intervals of 28 days and data plotted against this every 28 days.
I want to know if its possible to add a second line but with data plotted daily rather than every 28 days.
Thanks

Yes, you can! This type of series are called scatterLines and basically for each series you have to provide an array of pairs with the x and y values.
If for the first series you provide values 0, 28, 56... and for the second 0, 1, 2... You get what you want.
Example:
$("#chart").kendoChart({
series: [
{ type: "scatterLine", data: [[0, 4], [28, 2], [56, 3]] },
{ type: "scatterLine", data: [[1, 2], [2, 3]] }
]
});
Check it here: http://jsfiddle.net/U7SvD/

Related

Return a fixed sized list based on an other list

I am looking in Kotlin for a method who return me from a list a new list with a defined number of elements (for example 10).
Whatever the size of the list, the method would always return the same number of elements.
For example, suppose a list of 3000 elements, it would return me a list of 10 elements from indexes 0, 300, 600, 900, 1200,...
Is there an extension function for this?
That's kind of a specialised thing, so there's nothing (that I know of) in the standard library - but you could easily make your own extension function:
fun <T: Any> List<T>.sample2(count: Int): List<T> {
// this allows for a fractional step, so we get a more accurate distribution of indices
// with smaller lists (where count doesn't divide into the list size evenly)
val step = size / count.toFloat()
return List(count) { i -> elementAt((i * step).toInt()) }
}
You'll get repeats if your list is too small to provide count unique indices (e.g. your list has 9 items and you want 10), so you'd have to handle that if you want different behaviour, but I think this is the easiest way to do it
Here's an idea:
Take advantage of the method chunked(size: Int), which tries to depart a given collection into sub-collections of the given size.
That's not quite what you want, but you can use it in order to implement a custom extension function which does what you want, e.g. like this:
fun List<Int>.departInto(subListCount: Int) : List<List<Int>> {
// calculate the chunk size based on the desired amount of sublists
val chunkSize = this.size / subListCount
// then apply that value to the chunked method and return the result
return this.chunked(chunkSize)
}
Using this could look as follows:
fun main() {
// define some example list (of 30 elements in this case)
val someList: List<Int> = List(30, {it})
// use the extension function
val tenSubLists = someList.departInto(10)
// print the result(s)
println(tenSubLists)
}
The output of this code will be 10 sub-lists of 3 elements (your example of 3000 elements would then result in 10 sub-lists of 300 elements each):
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14], [15, 16, 17], [18, 19, 20], [21, 22, 23], [24, 25, 26], [27, 28, 29]]

Using Maxima, how can I combine two lists into one nested list?

I have one list of x-values and another for y-values. I would like these arranged in a 2 column matrix or a nested list (which I can easily turn into a matrix). In Mathematica, this is accomplished using Thread[x-values, y-values], but I can find no similar Maxima function.
I'm starting with these two lists,
Tx:[1,2,3,4,5,6,7,8,9,10];
Ty:[86,85,84,89,85,89,87,85,82,85];
and manually making this,
ListT: [[1,86],[2,85],[3,84],[4,89],[5,85],[6,89],[7,87],[8,85],[9,82],[10,85]];
so I can create a matrix using
MatrixT: apply('matrix,ListT);
Is there a 'quick' way to do this because my real data set has hundreds of data points that come to me in this fashion.?
I think an easy way to do that is to create a matrix which has 2 rows and many columns, and then transpose it to 2 columns and many rows:
MatrixT: transpose (matrix (Tx, Ty));
There are at least two other ways I can think of:
ListT: map (lambda ([a, b], [a, b]), Tx, Ty);
MatrixT: apply (matrix, ListT);
and
ListT: makelist ([Tx[i], Ty[i]], i, 1, length(Tx));
MatrixT: apply (matrix, ListT);
I use transpose pretty often to go back and forth between row-oriented and column-oriented variables. E.g., let's say you have a mymatrix3 with 3 columns and you want variables X, Y, and Z to be assigned the columns. You can say
[X, Y, Z]: args (transpose (mymatrix3));
since args(<some matrix>) returns a list of the rows of the matrix, and [X, Y, Z]: <some list of 3 things> represents parallel assignment.
May I ask for what purpose you are using Maxima? I am always interested to hear what people are working on. (I'm a Maxima developer and project administrator.)
I only found this way:
(%i1) Tx:[1,2,3,4,5,6,7,8,9,10];
(%o1) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
(%i2) Ty:[86,85,84,89,85,89,87,85,82,85];
(%o2) [86, 85, 84, 89, 85, 89, 87, 85, 82, 85]
(%i3) ListT:makelist([Tx[i],Ty[i]],i,1,length(Tx));
(%o3) [[1, 86], [2, 85], [3, 84], [4, 89], [5, 85], [6, 89], [7, 87], [8, 85], [9, 82], [10, 85]]

dc.js charts, how to get the intersection of multiple filters

I am wondering if anyone can help me with getting the intersection of multiple filters.
For example:
if I have following:
var ndx = crossfilter([
{id: 1, arrayVals: [1, 2]},
{id: 2, arrayVals: [2, 3]},
{id: 3, arrayVals: [1, 2, 3]}
]);
how do I get items with arrayVals that have 1 and 3? And how do I get the filter value onclick?
As far as I know, within a dc chart the filtering is "OR" and between dc charts, the filtering is "AND".
Thanks Millions,
Anney

Tensorflow - shuffle & split dataset of images and labels

New with Tensorflow, I'm using neural networks to classify images. I've got a Tensor that contains images, of shape [N, 128, 128, 1] (N images 128x128 with 1 channel), and a Tensor of shape [N] that contains the labels of the images.
I want to shuffle it all and split it between training and testing tensors (let's say 80%-20%). I didn't find a way to 'zip' my tensors to associate each image with its label (in order to shuffle images and labels the same way). Is it possible ? If not, how can I achieve that shuffling/splitting job ?
Thanks for any help !
Just use the same 'seed' keyword parameter value, say seed=8 in function
tf.random_shuffle for both labels and data.
ipdb> my_data = tf.convert_to_tensor([[1,1], [2,2], [3,3], [4,4],
[5,5], [6,6], [7,7], [8,8]])
ipdb> my_labels = tf.convert_to_tensor([1,2,3,4,5,6,7,8])
ipdb> sess.run(tf.random_shuffle(my_data, seed=8))
array([[5, 5],
[3, 3],
[1, 1],
[7, 7],
[2, 2],
[8, 8],
[4, 4],
[6, 6]], dtype=int32)
ipdb> sess.run(tf.random_shuffle(my_labels, seed=8))
array([5, 3, 1, 7, 2, 8, 4, 6], dtype=int32)
EDIT:
if you need random shuffling in runtime, where batches, say, will be shuffled randomly but differendly, you may use such a trick:
# each time shuffling pattern will be differend
# for now, it works
indicies = tf.random_shuffle(tf.range(8))
params = tf.convert_to_tensor([111, 222, 333, 444, 555, 666, 777, 888])
sess.run(tf.add(tf.gather(params, indicies), tf.gather(params, indicies) * 1000))
> array([555555, 444444, 666666, 222222, 111111, 888888, 333333, 777777], dtype=int32)
numbers consisting of the same digits show, that gather<-indicies take the same seed value

OpenSCAD how to access a value within a Matrix

How do I index a matrix in OpenSCAD or iterate through it in a loop?
I'm trying to either access and assign the values assigned to coordinates through the forloop to their single variables as below, or at least be able to access the values separately in the Matrix.
for ( coordinates = [ [ 15, 15, 2],
[ 15, -15, 2],
[ -15, -15, 2],
[ -15, 15, 2] ])
{
x = coordinates[0];
y = coordinates[1];
z = coordinates[2];
translate([x+4, y, z]){
cube([x,y,z]);
}
}
First off, standard variables are set at compile-time in OpenSCAD, not run-time (official documentation stating that), so you can't assign values to them in a loop. You'll have to inline references to coordinates to use the values in it.
The second issue is that you can't make a cube with a negative size, or so I'm guessing from the fact that I get no output from the second through fourth iterations of the loop as provided. You can wrap the values passed into cube in abs() calls to get the absolute value to ensure it's positive.
Here's a working sample of inlining the coordinates variable and using abs() to pass positive values to cube():
for ( coordinates = [ [ 15, 15, 2],
[ 15, -15, 2],
[ -15, -15, 2],
[ -15, 15, 2] ])
{
translate([coordinates[0] + 4, coordinates[1], coordinates[2]]) {
cube([abs(coordinates[0]), abs(coordinates[1]), abs(coordinates[2])]);
}
}

Resources