Solved

Density of selected values within file

Posted on 2011-02-14
7
359 Views
Last Modified: 2012-06-27
Hello experts!

Please have a look at the numbers attached to the code.


First number is amount of indexes.
The second number is index itself.
Indexes are valued from 0..7.

So for example:

19, 4

means that we have nineteen indexes with value of 4.


My task is to analyze the density of these indexes.
These density types should be calculated and taken into consideration:
(I want to find index values and position borders they appear)

- single indexes
- couples of indexes
- triples of indexes


So if we look for single indexes we should find out that we have high density of
indexes = 4 (look at line no.2) and indexes = 0 (look at line no. 6).

If we look for triples of indexes we should find out that we have high density
of indexes 0, 1, 7 (from line no. 5 to 66).

Search for couples will be similar as for triples.


How can I make such analysis in a smart way?
Is there any mathematical tool to do such things?


Thank you

panJames


1, 5
19, 4
2, 6
1, 2
1, 1
18, 0
1, 1
1, 0
1, 7
3, 0
1, 1
1, 7
1, 0
1, 1
1, 7
1, 0
1, 1
1, 7
5, 0
1, 1
1, 0
1, 7
2, 0
1, 1
1, 7
1, 1
2, 0
1, 7
5, 0
1, 1
1, 7
1, 0
1, 1
2, 0
1, 7
2, 0
1, 1
1, 7
2, 0
1, 1
2, 0
1, 7
1, 0
1, 1
1, 0
1, 7
1, 1
1, 7
3, 0
1, 1
1, 7
1, 1
4, 0
1, 7
1, 1
1, 7
1, 1
1, 7
2, 0
1, 1
1, 7
4, 0
1, 1
1, 7
2, 0
1, 7
1, 5
2, 6
1, 5
2, 6

Open in new window

0
Comment
Question by:panJames
7 Comments
 
LVL 22

Expert Comment

by:Flyster
Comment Utility
If you have Microsoft Access, you can create a query that will group and count the number of indexes. Using the data provide, I came up with the following results:

22,0
20,1
1,2
1,4
3,5
3,6
20,7

This took all of 5 minutes. If this is what you're looking for, I can provide you with some guidance on how to create the table and query.

Flyster
0
 
LVL 37

Expert Comment

by:TommySzalapski
Comment Utility
If you don't have Access, you most likely have Excel (or OpenOffice or something that does the same thing). These programs will open the file perfectly (they are built to understand the commas as separating cells). They can do quite a bit of analysis with built-in functions and you can write scripts to do anything that computers are capable of doing.

In a string like 0,1,7,0,1,7,0,1,7, 0. Should the 0,1,7 and 1,7,0 triples both be counted (3 each)?
Does 19,4 indicate a bunch of triples of 4?
The required analysis is not yet clear.
0
 

Author Comment

by:panJames
Comment Utility
Flyster: Thank you for your answer.

What I need here is algorithm to solve problem.


panJames
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 37

Expert Comment

by:TommySzalapski
Comment Utility
Is 4,0 essentially the same as 0,0,0,0? So do you need to look at triples like 0,0,0? We need more specifications before we can help with algorithms.

Also, what platform are you working with? C++, Excel, VBScript, pen and paper, etc
0
 

Author Comment

by:panJames
Comment Utility
@TommySzalapski:

"Is 4,0 essentially the same as 0,0,0,0?" <- not really.

I should explain it better.

Values attached describe another file with values inside [values: 0..7]

First file:

0
0
0
0
1
1
2
2
2

it means that in the second file we get:

4, 0
2, 1
3, 2

so the second file is like a summary of the first file.

Algorithm will be using C++

panJames
0
 
LVL 45

Expert Comment

by:patrickab
Comment Utility
panJames,

Copy the list into Excel and use Data/Text to columns to split the data into 2 columns - Number of Indexes and Index. Having done that set up a small table listing the indexes and use this formula to summarise the results:

=SUMIF($B$1:$B$70,D2,$A$1:$A$70)

It's in the atteched Excel file.

Patrick
panJames-01.xls
0
 
LVL 37

Accepted Solution

by:
TommySzalapski earned 500 total points
Comment Utility
Single indexes is easy. You just sum them all.
In C++ I would use an array like
int indexes[8];
for(int i = 0; i < 8; ++i)
  indexes[8] = 0;

Then just loop through the input and if you see 4, 3 do
indexes[3] += 4
etc.
But this is the easy part

For triples you need to look at each index individually. I would use an array of arrays of arrays (actually I would call it a tree). So if you see 4, 3 you'll need to send all 4 of the 3s one at a time into your function.
You would need to track what the last two were. If I was implementing it for real, I would use a circular queue, but if you only need to deal with up to triples I would just do it the easy way.
Something like this:
(note: set up constants where they should be etc)
const int INDEXES = 8;//You really should use a constant for the 8

int history[3];
int triples[INDEXES][INDEXES][INDEXES];
memset(triples, 0, INDEXES*INDEXES*INDEXES*sizeof(int)); //set all to 0

//Write your code to read the values in.
//Get the first three before you start this part

triples[history[0]][history[1]][history[2]]++;

//This could be a loop (and really should be)
history[0] = history[1];
history[1] = history[2];

history[2] = newValue;

//Then you can do something like
for(int i = 0; i < INDEXES; ++i)
  for(int j = 0; j < INDEXES; ++j)
    for(int k = 0; k < INDEXES; ++k)
      if(triples[i][j][k] > 0)
        printf("%d, %d, %d: %d", i, j, k, triples[i][j][k];

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
CAGR Calculation For SIP 13 60
Volume Calculation 14 44
2k Power n formula 2 33
Currency Conversion? 1 34
Okay. So what exactly is the problem here? How often have we come across situations where we need to know if two strings are 'similar' but not necessarily the same? I have, plenty of times. Until recently, I thought any functionality like that wo…
Article by: Nadia
Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now