Re: [julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-05 Thread Ahmed Mazari
train a neural net with these data.

On Tue, Jul 5, 2016 at 12:43 PM, Andre Bieler 
wrote:

> Can you tell me what you will be doing with this tree after everything is
> set up correctly?


Re: [julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-05 Thread Andre Bieler
Can you tell me what you will be doing with this tree after everything is set 
up correctly?

Re: [julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-05 Thread Ahmed Mazari
the objective is to get 100 (leafs) vectors (which are not equal in length)
of data  from child and root.
initial data is in the root
then the data is divided between childs (the size of each vector may varies
from 1 child to another)
each child share it's data with its own leaf (the size of each vector may
varies from on leaf to another )

the objective is to do clustering l need this architecture. Any ideas how
to get this data ?


Re: [julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-05 Thread Andre Bieler
Ahmed,

is it necessary that the data is stored in all 3 levels? (root has data, 
child has data, leaf has data)
Is it not good enough if the data is stored in the leafs only?

Maybe you can explain what your "end goal" is?


Re: [julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-05 Thread Ahmed Mazari
But l have encountered a problem when distributing data from root to child 
then to leafs. l'm looking for something like this: 

*level 0root :   *data= rand(1)  # generate 1 random 
values
*level 1  10 child *  for each child attribute a certain number of 
generated values , divide the data generated in the root between the childs
   for example child 1= 1000  child 2 = 500  child3 = 750   
child4 = 1500 child 5= 2000 child6 = 250 child 7= 1500 child8 = 500 child 
9= 1000 child 10= 500
the sum gives you = 1 values

*level 2 leafs  :*
each child has a certin number of leafs . let's suppose that child 1 has 4 
leafs. then data should be shared as folllows :
child 1 = 1000 values

leaf 1 = 500  leaf 2 = 200 leaf 3= 100  leaf 4 = 150 leaf 5 = 50   and the 
sum equal to 1000 (child 1 = 1000 values)

do that for each child.

l'm trying to do that since yesterday but l failed, l keep trying , any 
help please


On Monday, July 4, 2016 at 2:09:25 PM UTC+2, Andre Bieler wrote:
>
> Well for 1) this is pretty much exactly what is being done in my example 
> code.
> The difference is that it prints out the content of "data". (But I put the 
> index of
> each child into that "data" varialbe)
>
> My suggestion is that you insert a new field in the MyNode type, this 
> variable
> can then hold an index. E. g. for child1 this index is 1, etc.
>
> Then do the same thing my example does in the end, but print out this 
> index instead
> of data.
> I think you should try implementing this on you own, it will probably help 
> you understand
> what is going on in the code. If you have problems doing so you can come 
> back with more
> questions.
>
> Cheers,
> Andre
>


Re: [julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-05 Thread Ahmed Mazari
hello, 

l fixed the problem by adding a function called data_node() as follows :

function data_node(node)
 
  println("data : ", node.data)
  println("index ", node.index)
end

for i in 1:nChildren
for k in 1:root.child[i].nchild
  data_node(root.child[i].child[k])
end
end



On Monday, July 4, 2016 at 4:39:54 PM UTC+2, Ahmed Mazari wrote:
>
> The idea that comes to my mind is the following : 
> add a new variable to MyNode type wich is  index, 
> type MyNode{T}
> data::Vector{T}
> level::Int
> child :: Vector{MyNode}
> nchild :: Int
> index :: Int
> end
>
> function node_info(node)
>   println("Level: ", node.level)
>   println("nChildren: ", node.nchild)
>   println("data : ", node.data)
>   println("index ", node.index)
> end
>
> # set an empty list to store the leafs of each child 
> for i in 1:nChildren 
>  list_leafs_of_child[i]= Int64[] # for instance list_leafs_of_child[1] = 
> [2, 5,4,9 ..]
> end
>
> for i in 1:nChildren
> for j in 1:nGrandChildren
>  if contains(grand_children_list[i], j) # check whether  j is contained 
> in grand_children_list[i] if so add j to the list of leafs of child[i]
> # contains is a function in julia 
>   list_leafs_of_child[i]= [list_leafs_of_child  j]  #  add j to the list 
>   , j : new element , list_leafs_of_child  : the ancient list 
> end
> end
>
> but it's not working my function is not well my loop is not well defined. 
> sorry for these stupid questions. l'm a dummy in julia hope that l don't 
> bother you
>
>
>
>
> On Monday, July 4, 2016 at 2:09:25 PM UTC+2, Andre Bieler wrote:
>>
>> Well for 1) this is pretty much exactly what is being done in my example 
>> code.
>> The difference is that it prints out the content of "data". (But I put 
>> the index of
>> each child into that "data" varialbe)
>>
>> My suggestion is that you insert a new field in the MyNode type, this 
>> variable
>> can then hold an index. E. g. for child1 this index is 1, etc.
>>
>> Then do the same thing my example does in the end, but print out this 
>> index instead
>> of data.
>> I think you should try implementing this on you own, it will probably 
>> help you understand
>> what is going on in the code. If you have problems doing so you can come 
>> back with more
>> questions.
>>
>> Cheers,
>> Andre
>>
>

Re: [julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-04 Thread Ahmed Mazari
The idea that comes to my mind is the following : 
add a new variable to MyNode type wich is  index, 
type MyNode{T}
data::Vector{T}
level::Int
child :: Vector{MyNode}
nchild :: Int
index :: Int
end

function node_info(node)
  println("Level: ", node.level)
  println("nChildren: ", node.nchild)
  println("data : ", node.data)
  println("index ", node.index)
end

# set an empty list to store the leafs of each child 
for i in 1:nChildren 
 list_leafs_of_child[i]= Int64[] # for instance list_leafs_of_child[1] = 
[2, 5,4,9 ..]
end

for i in 1:nChildren
for j in 1:nGrandChildren
 if contains(grand_children_list[i], j) # check whether  j is contained in 
grand_children_list[i] if so add j to the list of leafs of child[i]
# contains is a function in julia 
  list_leafs_of_child[i]= [list_leafs_of_child  j]  #  add j to the list   
, j : new element , list_leafs_of_child  : the ancient list 
end
end

but it's not working my function is not well my loop is not well defined. 
sorry for these stupid questions. l'm a dummy in julia hope that l don't 
bother you




On Monday, July 4, 2016 at 2:09:25 PM UTC+2, Andre Bieler wrote:
>
> Well for 1) this is pretty much exactly what is being done in my example 
> code.
> The difference is that it prints out the content of "data". (But I put the 
> index of
> each child into that "data" varialbe)
>
> My suggestion is that you insert a new field in the MyNode type, this 
> variable
> can then hold an index. E. g. for child1 this index is 1, etc.
>
> Then do the same thing my example does in the end, but print out this 
> index instead
> of data.
> I think you should try implementing this on you own, it will probably help 
> you understand
> what is going on in the code. If you have problems doing so you can come 
> back with more
> questions.
>
> Cheers,
> Andre
>


Re: [julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-04 Thread Andre Bieler
Well for 1) this is pretty much exactly what is being done in my example 
code.
The difference is that it prints out the content of "data". (But I put the 
index of
each child into that "data" varialbe)

My suggestion is that you insert a new field in the MyNode type, this 
variable
can then hold an index. E. g. for child1 this index is 1, etc.

Then do the same thing my example does in the end, but print out this index 
instead
of data.
I think you should try implementing this on you own, it will probably help 
you understand
what is going on in the code. If you have problems doing so you can come 
back with more
questions.

Cheers,
Andre


Re: [julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-04 Thread Ahmed Mazari
Hello Andre thantk you a lot , when l run the code l think it's gives what
l'm looking for. but l have trouble to understand the code in order to add
the following instruction :
1) l need to print a list of leaf of each child by retrieving the indexes
:  for example
child 1 :  [leaf 1,  leaf 5 , ]
child 2 : [leaf 3, leaf 4 ]

2) for each leaf print the following :
leaf 1 is linked to child 3
leaf 2 is linked to child 5
and so on

On Sun, Jul 3, 2016 at 4:35 PM, Andre Bieler 
wrote:

> and maybe someday I will be smart enough for syntax highlighting... maybe..
>


Re: [julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-03 Thread Andre Bieler
and maybe someday I will be smart enough for syntax highlighting... maybe..


Re: [julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-03 Thread Andre Bieler
Hi Ahmed, sorry for the late answer, but
it is a busy weekend... I am not sure I understand
your question, but the following for loop connects the leafs
to the children.

for i in 1:nChildren
 root.child[i].child = all_leafs[i]
end

Here a full example code where some information is printed in the end. I 
call leafs now grand-children, because it is just children of the children.
I hope this makes my attempt a little more clear.
type MyNode{T}
data::Vector{T}
level::Int
child :: Vector{MyNode}
nchild :: Int
end
MyNode() = MyNode(Float64[], 0, MyNode[], 0)

function add_children!(parentNode, nChildren)
  data = Float64[] # do something with the data here, I dont know whats 
needed..
  level = parentNode.level + 1
  for i in 1:nChildren
child = MyNode(data, level, MyNode[], 0)
push!(parentNode.child, child)
  end
  parentNode.nchild += nChildren
end

function node_info(node)
  println("Level: ", node.level)
  println("nChildren: ", node.nchild)
  println("data : ", node.data)
end

nChildren = 2
# create root node
root = MyNode()

# add children to root
add_children!(root, nChildren)

# create an empty list for each child, in this list we can then
# later insert grand_children (grand-children = leafs)
# In the end this list will be used like this:
# g_children_list[1] = list of all grand-children of child 1.
# g_children_list[2] = list of all grand-children of child 2.
grand_children_list = Any[MyNode[] for i in 1:nChildren]

# set the total number of grand-children (= total number of leafs)
# then create all of them and isert them into the list.
nGrandChildren = 10
for i in 1:nGrandChildren
  # create a grand_child (= leaf)
  data = Float64[i] # here I just fill the grand-children-index into data.
  level = 2
  grand_child = MyNode(data, level, MyNode[], 0)

  # randomly choose to which of the children it belongs
  childIndex = rand(1:nChildren)

  # add the grand_child to the list of grand_children of the randomly 
picked child
  push!(grand_children_list[childIndex], grand_child)
end

# now loop over all children and assign all the grand-children to them.
for i in 1:nChildren
  root.child[i].child = grand_children_list[i]
  root.child[i].nchild = length(grand_children_list[i])
end


node_info(root)
println("")
node_info(root.child[1])
println("")
for i in 1:root.child[1].nchild
  node_info(root.child[1].child[i])
  println(" - - - - - - - - - - - - ")
end


Maybe my attempts to be uber-clear are not helping. Someone else has a 
better/clearer idea? :)




Re: [julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-01 Thread Ahmed Mazari
l don't understand your code!!  how do you connect each child to its leafs ?

On Fri, Jul 1, 2016 at 4:42 PM, Ahmed Mazari 
wrote:

> ha  you should just reply from the google group rather than from your
> inbox mail. then click on { } to highlight the syntax
>
> On Fri, Jul 1, 2016 at 4:38 PM, Andre Bieler 
> wrote:
>
>> ah for &^%$@@ sake how do you enable syntax highlighting?? I thought
>> ```julia would do the trick??
>> If you tell me the secret I can re-post my previous message more nicely :)
>>
>
>


Re: [julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-01 Thread Ahmed Mazari
ha  you should just reply from the google group rather than from your inbox
mail. then click on { } to highlight the syntax

On Fri, Jul 1, 2016 at 4:38 PM, Andre Bieler 
wrote:

> ah for &^%$@@ sake how do you enable syntax highlighting?? I thought
> ```julia would do the trick??
> If you tell me the secret I can re-post my previous message more nicely :)
>


Re: [julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-01 Thread Ahmed Mazari
1) yes they are of the same type as root and child . the leaf is the last
level of the tree so it doesn't have any child
2) yes no children with zero leaf at least one leaf

On Fri, Jul 1, 2016 at 4:37 PM, Andre Bieler 
wrote:

> I think I start seeing what you want. A few questions:
>
> 1) Can the leafs be of the same type as the root and child?
> 2) Does every child need to have one child at least? (= no child with zero
> leafs)
>
> you can do the following:
>
> ```julia
>
> # this generates a list of empty vectors that can hold MyNode types, each
> of these vectors
> # will then be filled with leafs
> # once all vectors are filled with leafs we can distribute them to the
> children
>
> all_leafs = Any[MyNode[] for i in 1:nChildren]
>
> for i in 1:100
>   childIndex = rand(1:nChildren) # pick to which child this leaf will go
>   #create your leaf here with necessary stuff like above
>   leaf=MyNode(data,level, MyNode[], 0)
>   push!(all_leafs[childIndex], leaf)
> end
> ```
>
> then you can distribute those leafs:
>
> ```julia
>
> for i in 1:nChildren
>   root.child[i].child = all_leafs[i]
> end
> ```
>


[julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-01 Thread Andre Bieler
ah for &^%$@@ sake how do you enable syntax highlighting?? I thought 
```julia would do the trick??
If you tell me the secret I can re-post my previous message more nicely :)


[julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-01 Thread Andre Bieler
I think I start seeing what you want. A few questions:

1) Can the leafs be of the same type as the root and child?
2) Does every child need to have one child at least? (= no child with zero 
leafs)

you can do the following:

```julia

# this generates a list of empty vectors that can hold MyNode types, each 
of these vectors
# will then be filled with leafs
# once all vectors are filled with leafs we can distribute them to the 
children

all_leafs = Any[MyNode[] for i in 1:nChildren]

for i in 1:100
  childIndex = rand(1:nChildren) # pick to which child this leaf will go
  #create your leaf here with necessary stuff like above
  leaf=MyNode(data,level, MyNode[], 0)
  push!(all_leafs[childIndex], leaf)
end
```

then you can distribute those leafs:

```julia

for i in 1:nChildren
  root.child[i].child = all_leafs[i]
end
```


[julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-01 Thread Ahmed Mazari
Let's define the function that allows to associate randomly a certain 
number of leafs for each child under a constraint : the total number of 
leafs is 100 and the function that allows to add_link between each child 
with its leafs. Please don't hesitate to modify the code, there is some 
improvement to do. hope the problem is more clear for you

function random_edges(nleafs) #nleafs = 100
x=rand(1:nleafs,(1,10)) # (1,10) to tell that we have 10 childs 
while (sum(x) !== nleafs) # the while loop allows to get a tuple of 10 
values where each value represents the number of 
  # of leafs for each child where sum(x)= nleafs
x=rand(1:nleafs,(1,10))
end
return x
end

y=random_edges(100)
1x10 Array{Int64,2}:
 3  1  7  5  13  7  30  6  18  10
sum(y)
100

# child 1 has 3 leafs , child 2 has 1 leaf, child 3 has 7 leafs .. 
child 10 has ten leafs 

# here we need to define the function that allows to link each child to its 
leafs and transfer data from each child to its leafs
# some improvement to do 



x=random_edges(100) # 100 number of leafs needed


function  add_leafs!(childs,x)  #x : the output of the function 
random_edges  childs : the output of the function add_children!
data =  child data ? # the data of each child  
level = childs.level +1  # since the level of child is 1 then the level of 
leafs is 2
h = 0
   for i in 1:length(x)
   while h < x[i]# how to link each child to its 
leafs. for example i= 1 x[1]= 3 then we need to have 3 leafs for child 1 
and so on ...
  leaf=MyNode(data,level, MyNode[], 0)
   push!(childs.leaf,leaf)
   h += 1
end 
   end
 
   
end



Thank you
On Friday, July 1, 2016 at 12:41:09 PM UTC+2, Andre Bieler wrote:
>
> Well the child can also have children, just like in your graph you 
> attached. This is then one level down in your graph. 
>
> Note that the root is of the same type as the children. (MyNode can be 
> parent, child, grandchild etc.) The children are just put inside the root. 
> Then you can continue and put children into these children. This is how you 
> get the tree structure.
>
> I hope this is somehow clear.
>
> Best,
> Andre
>
>

[julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-01 Thread Andre Bieler
Well the child can also have children, just like in your graph you attached. 
This is then one level down in your graph. 

Note that the root is of the same type as the children. (MyNode can be parent, 
child, grandchild etc.) The children are just put inside the root. Then you can 
continue and put children into these children. This is how you get the tree 
structure.

I hope this is somehow clear.

Best,
Andre

[julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-07-01 Thread Ahmed Mazari
hi,
l don't understand what you're doing here.  add_children!() need to have as 
a parameter a root (node parent) not child, isn't it ?
*for child in root.child*
*  add_children!(child, 10)*
*end*



On Wednesday, June 29, 2016 at 4:53:55 PM UTC+2, Ahmed Mazari wrote:
>
> Hello ,
>  
>
> I need to implement a tree in Julia with depth of l=3. Initially the root 
> node has a vector of m=1 random values (k=rand(m)).Then this vector is 
> divided into k=10 partitions where each node child has a vector of n=1000 
> values. Finally the leafs are connected to a given child node.
>
> each partition (child node) has 10 leafs where each leaf has a vector of 
> g= 100 values. Since each child node has a vector of 1000 values.this 
> latter is shared with its leafs 100 values for each leaf. so the structure 
> of the tree is as follows: 
>
>
>
> level 0 root node : vector of 1 values
>
> level 110 child node each one of 1000 
> values
>
> level 2   10 leafs for each child node of 100 values (that 
> means we have in total we have 100 leafs )
>
>
>
> Thank you for helps
>


[julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-06-30 Thread Ahmed Mazari


On Thursday, June 30, 2016 at 2:12:30 PM UTC+2, Ahmed Mazari wrote:
>
> Hi Andre. 
> You will fnd attached my files and a picture that illustrates the tree 
> structure l'm looking for.
> file 1 : somme comments on your codes
> file 2 : my code to be improved.
>
> For the part of your code. We should add child, number of child and data.
> the structure seems to be appropriate from my point of view 
>
> type MyNode{T}
> data:: T
> level::Int
> child :: Vector{MyNode}
> nchild :: Int
> nLeafs::Int
> leafs::Vector{MyNode}
> end
>  1) What's the purpose of this line  MyNode() = MyNode(0,0,MyNode[]) ?
> 2) for level 0 it's the root as you defined it :
>
> root = MyNode(0,N, [MyNode() for i in 1:N])
>
> but for level 1 it will be child :
> child= MyNode(..)
>
> for node in root.child
>   # we have to link root to child and transferer data 
>  # need to define function addEdge()
>
>
> end
>
> level 2 : 
> leaf= MyNode(..)
>  
> for leaf in root.leaf
>   # we have to link childs to their own leafs and transferer data 
>  # need to define function addEdge()
> end
>
>
>
> On Wednesday, June 29, 2016 at 7:47:25 PM UTC+2, Andre Bieler wrote:
>>
>> Not very elegant, but maybe something like this?
>>
>> type MyNode
>> level::Int
>> nLeafs::Int
>> leafs::Vector{MyNode}
>> end
>>
>> MyNode() = MyNode(0,0,MyNode[])
>>
>> N = 100
>> root = MyNode(0,N, [MyNode() for i in 1:N])
>>
>> then you can go on and define the 1st level with a for loop and so on.
>> Because it is only 3 levels I guess you can manually set it up, otherwise
>> you want to use recursive functions or so.
>>
>> For 2nd level:
>>
>> for node in root.leafs
>>   do_whatever
>> end
>>
>

files2.jl
Description: Binary data


file1.jl
Description: Binary data


[julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-06-30 Thread Ahmed Mazari
Hi Andre. 
You will fnd attached my files and a picture that illustrates the tree 
structure l'm looking for.
file 1 : somme comments on your codes
file 2 : my code to be improved.

For the part of your code. We should add child, number of child and data.
the structure seems to be appropriate from my point of view 

type MyNode{T}
data:: T
level::Int
child :: Vector{MyNode}
nchild :: Int
nLeafs::Int
leafs::Vector{MyNode}
end
 1) What's the purpose of this line  MyNode() = MyNode(0,0,MyNode[]) ?
2) for level 0 it's the root as you defined it :

root = MyNode(0,N, [MyNode() for i in 1:N])

but for level 1 it will be child :
child= MyNode(..)

for node in root.child
  # we have to link root to child and transferer data 
 # need to define function addEdge()


end

level 2 : 
leaf= MyNode(..)
 
for leaf in root.leaf
  # we have to link childs to their own leafs and transferer data 
 # need to define function addEdge()
end



On Wednesday, June 29, 2016 at 7:47:25 PM UTC+2, Andre Bieler wrote:
>
> Not very elegant, but maybe something like this?
>
> type MyNode
> level::Int
> nLeafs::Int
> leafs::Vector{MyNode}
> end
>
> MyNode() = MyNode(0,0,MyNode[])
>
> N = 100
> root = MyNode(0,N, [MyNode() for i in 1:N])
>
> then you can go on and define the 1st level with a for loop and so on.
> Because it is only 3 levels I guess you can manually set it up, otherwise
> you want to use recursive functions or so.
>
> For 2nd level:
>
> for node in root.leafs
>   do_whatever
> end
>


[julia-users] Re: How to make a tree datastructure with vector data in JULIA ?

2016-06-29 Thread Andre Bieler
Not very elegant, but maybe something like this?

type MyNode
level::Int
nLeafs::Int
leafs::Vector{MyNode}
end

MyNode() = MyNode(0,0,MyNode[])

N = 100
root = MyNode(0,N, [MyNode() for i in 1:N])

then you can go on and define the 1st level with a for loop and so on.
Because it is only 3 levels I guess you can manually set it up, otherwise
you want to use recursive functions or so.

For 2nd level:

for node in root.leafs
  do_whatever
end