Pages: [1]
  Print  
Author Topic: Count a specific number in a set of attributes  (Read 986 times)
Shubha
Full Member
***
Posts: 141


« on: June 05, 2009, 10:20:23 AM »

Hi,

I have a set of attributes and I need to create a new attribute which counts the number of zeros appearing in all the rows over the set of attributes.

I tried some like the below.

Code:
<operator name="Root" class="Process" expanded="yes">
    <operator name="ExampleSetGenerator" class="ExampleSetGenerator">
        <parameter key="target_function" value="random"/>
        <parameter key="number_examples" value="10"/>
    </operator>
    <operator name="Real2Integer" class="Real2Integer">
        <parameter key="round" value="true"/>
    </operator>
    <operator name="AttributeAggregation" class="AttributeAggregation" breakpoints="before">
        <parameter key="attribute_name" value="new"/>
        <parameter key="aggregation_attributes" value="att.*"/>
        <parameter key="aggregation_function" value="count"/>
    </operator>
</operator>


Though the AttrbuteAggregation operator has the COUNT function, it cannot count the occurance of a specific number over the set of attributes.

Thanks for your help,
Shubha
« Last Edit: June 05, 2009, 02:01:17 PM by Shubha » Logged
haddock
Hero Member
*****
Posts: 853



WWW
« Reply #1 on: June 05, 2009, 04:39:08 PM »

Hi Shubha,

Nice problem for regex folk! Does this do what you want? Haven't checked it thoroughly, but you get the idea..

Code:
<operator name="Root" class="Process" expanded="yes">
    <operator name="Set what you want to count" class="SingleMacroDefinition">
        <parameter key="macro" value="Look_for"/>
        <parameter key="value" value="-1"/>
    </operator>
    <operator name="ExampleSetGenerator" class="ExampleSetGenerator">
        <parameter key="target_function" value="random"/>
        <parameter key="number_of_attributes" value="10"/>
    </operator>
    <operator name="IdTagging" class="IdTagging">
    </operator>
    <operator name="Real2Integer" class="Real2Integer">
        <parameter key="round" value="true"/>
    </operator>
    <operator name="IOStorer" class="IOStorer">
        <parameter key="name" value="bla"/>
        <parameter key="io_object" value="ExampleSet"/>
        <parameter key="remove_from_process" value="false"/>
    </operator>
    <operator name="Numerical2Polynominal" class="Numerical2Polynominal">
    </operator>
    <operator name="Replace what you are counting with A" class="Replace">
        <parameter key="attributes" value=".*"/>
        <parameter key="replace_what" value="%{Look_for}"/>
        <parameter key="replace_by" value="A"/>
    </operator>
    <operator name="Get rid of all else" class="Replace">
        <parameter key="attributes" value=".*"/>
        <parameter key="replace_what" value="A[0-9]+|-A|[-]*[0-9]+A|\-|[0-9]+"/>
    </operator>
    <operator name="Replace A with 1" class="Replace">
        <parameter key="attributes" value=".*"/>
        <parameter key="replace_what" value="A"/>
        <parameter key="replace_by" value="1"/>
    </operator>
    <operator name="Add up the 1's" class="AttributeAggregation">
        <parameter key="attribute_name" value="Count of %{Look_for}"/>
        <parameter key="aggregation_attributes" value="att.*"/>
        <parameter key="aggregation_function" value="count"/>
    </operator>
    <operator name="FeatureNameFilter" class="FeatureNameFilter">
        <parameter key="skip_features_with_name" value="att.*"/>
    </operator>
    <operator name="IORetriever" class="IORetriever">
        <parameter key="name" value="bla"/>
        <parameter key="io_object" value="ExampleSet"/>
    </operator>
    <operator name="ExampleSetJoin" class="ExampleSetJoin">
        <parameter key="remove_double_attributes" value="false"/>
    </operator>
</operator>

Good weekend to all!

PS Last edit I think covers most cases, also last version only worked on enterprise, as it used numerica2formattednominal, using numerica2polynominal seems to work OK.

« Last Edit: June 08, 2009, 09:24:05 AM by haddock » Logged

Where is the wisdom we have lost in knowledge?
Where is the knowledge we have lost in information?

T.S.Eliot ~ Choruses from the Rock 1934
Shubha
Full Member
***
Posts: 141


« Reply #2 on: June 08, 2009, 01:53:39 PM »

That was interesting...  Thanks

Shubha
Logged
Pages: [1]
  Print  
 
Jump to: