Orange Forum • View topic - Would like and example of Descriptor.make()

Would like and example of Descriptor.make()

A place to ask questions about methods in Orange and how they are used and other general support.

Would like and example of Descriptor.make()

Postby bricklemacho » Fri Nov 02, 2012 10:20

I need to concatenate to tables. The table are generated from my own widget which creates a feature vector of an image. I am able to create the table, but not concatenate another table form a different flow/stream on the Orange canvas.

This post viewtopic.php?f=3&t=1078&p=2965 suggest to use Descriptor.make() and reading the documentation I think I understand why. I have followed the example in f the documentation. Here is my best attempt at creating a table using Descriptor.make():

descriptor, res = Orange.feature.Descriptor.make("a", Orange.feature.Type.Discrete, ['mean','variance','skew'])

domain = Orange.data.Domain(descriptor) # Is this correct way to use descriptor?

fv = [[1,2,3]] # Create some values

data = Orange.data.Table(domain,fv)


Which results the following error:

IndexError: invalid list size (got 3, expected 1 items) (at example 0)


I seem to be conceptually missing something. Can someone provide me an example using Descriptor.make() that allows me to add instances to a table using the descriptor from Description.make()?

Appreciate any help.

Brickle.

Re: Would like and example of Descriptor.make()

Postby Ales » Fri Nov 02, 2012 12:03

bricklemacho wrote:domain = Orange.data.Domain(descriptor) # Is this correct way to use descriptor?
For some strange reason apparently this works. But in general the Domain constructor takes a sequence of descriptors as the first argument, so please use
Code: Select all
domain = Orange.data.Domain([descriptor])
(even for a single descriptor)

bricklemacho wrote:fv = [[1,2,3]] # Create some values

data = Orange.data.Table(domain,fv)
This is the problem. You created a domain with a single feature (column) but are passing a table (list of lists) with three columns. Also note that value indices are zero based. Try this
Code: Select all
fv = [[0], [1], [2]] # Create some values
data = Orange.data.Table(domain,fv)

# Equivalent to
# fv = [['mean'], ['variance'], ['skew']]
# data = Orange.data.Table(domain,fv)


Of course I am assuming you are trying to create a table with a single column 'a' (that can take one of three values). Or are you trying trying to create a table with three columns?

Re: Would like and example of Descriptor.make()

Postby bricklemacho » Fri Nov 02, 2012 13:10

Thanks for a quick reply.

Of course I am assuming you are trying to create a table with a single column 'a' (that can take one of three values). Or are you trying trying to create a table with three columns?


Sorry for the confusion, I am trying to create a table with three columns in this example. Here what I currently doing in the widget:


Code: Select all
feature_vector = [ self.describe(image.data, self.label) for image in self.images]
descriptor = [Orange.feature.Descriptor(Orange.feature.Continuous, [x]) for x in ['mean', 'variance', 'skew']]
descriptor.append(Orange.feature.String('Label')) # Class label
domain = Orange.data.Domain(descriptor) 
self.data = Orange.data.Table(domain,feature_vector)


When I send self.data to the "Data Table" widget is displays as a 4 column table with the last being the class label as I expect. I do this for each class, each from their own flow/stream on the canvas. As noted I can't concatenate the tables because even tho the "names" of the variable match the "descriptors" are different. Hence why I am trying Descriptor.make() (and the main reason for this thread) Perhaps it would be easier to write my own bespoke concatenate widget?

At the risk of further exposing my lack of Python knowledge, when I try
Code: Select all
domain = Orange.data.Domain([descriptor])

I get the following error:
Code: domain = Orange.data.Domain([descriptor])
TypeError: invalid type for variable


Thanks again for your help.

Re: Would like and example of Descriptor.make()

Postby Ales » Fri Nov 02, 2012 13:39

Try this
Code: Select all
feature_vector = [ self.describe(image.data, self.label) for image in self.images]

# Create/reuse 'mean', 'variance' and 'skew' feature descriptors.
descriptors_and_status = [Orange.feature.Descriptor.make(x, Orange.feature.Type.Continuous)
                          for x in ['mean', 'variance', 'skew']]

# Get rid of status codes from the 'make' calls.
descriptors = [pair[0] for pair in descriptors_and_status]

descriptors.append(Orange.feature.String('Label')) # Class label
# You could also reuse the 'Label' descriptor
# descriptors.append(Orange.feature.Descriptor.make('Label', Orange.feature.Type.String)[0])

domain = Orange.data.Domain(descriptors)
self.data = Orange.data.Table(domain,feature_vector)

Re: Would like and example of Descriptor.make()

Postby bricklemacho » Fri Nov 02, 2012 14:00

Thank you.


Return to Questions & Support



cron