I have a situation where multiple inputs (rows) makes up the single output result.
My problem is similar to this one:
How to train a machine/deep learning model with data that has multiple input rows per day but only one row of label/ground-truth (output) data per day but does not refer to time series, only spatial data.
Let say I want to predict a value of imision in some central points. Each of them depends on a set of margin points (emitters) and their properties like distance, emission rate, topographic obstacles. Each connection between central and margin points constitutes one row, so for the single central point, I will have many rows of data.
It gives a table form of
<style>
th, td {
border:1px solid black;
text-align:center;
}
</style>
<table>
<tr>
<th>inp1</th>
<th>inp2</th>
<th>...</th>
<th>inpn</th>
<th>Output</th>
</tr>
<tr>
<td>x11</td>
<td>x12</td>
<td>...</td>
<td>x1n</td>
<td rowspan=4>y1</td>
</tr>
<tr>
<td>x21</td>
<td>x22</td>
<td>...</td>
<td>x2n</td>
</tr>
<tr>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr>
<td>xm1</td>
<td>xm2</td>
<td>...</td>
<td>xmn</td>
</tr>
<tr>
<td>x201</td>
<td>x202</td>
<td>...</td>
<td>x20n</td>
<td rowspan=4>y2</td>
</tr>
<tr>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
</table>
For example:
|no| distance| emission rate| substance| ....|
1| 100|5.44| aaa | ....|
2| 100|5.44| aaa | ....|
Both rows 1 and 2 make the single output of some y1. If only one row of the above was considered the output would be different than the result with two rows (!=y1). Then other rows (3, 4, 5, 6) make another single output of y2. And so on.
Are there any deep/ machine learning solutions/ topologies for this?
I know that the topic has already been discussed, but the only solutions I found was to concatenate many rows into one or to aggregate values of particular parameters (like sum, median, etc) which may be insufficient or impossible in my case.
I'm wondering whether there is something new in this topic, especially since my case is not the only one.
Related
I'm having difficulty figuring out how to split the following array and converting it into a format, so I can build an Active Record array of hashes.
My issue stems from writing an application that relies on Nokogiri to scrape information from the web. The data in each row of a table I'm trying to extract, is jammed into a single <td> element. Every row has only one <td> element.
EDIT:
The first webpage contains a <ul> list of a few hundred items and a link to its details page. I iterate through each item, using the link to access the details page for parsing. The table element I'm parsing below is from the details page. If you look at the output of split_array, I give the complete data of the first row (Level 1), then part of the second row (Level 2) to show that it is identical in structure but not in value. Solving the problem for the first row, solves the problem for all 6 rows.
<td>
Level 1
<br>
Attribute A: 24%
<br>
Attribute B: 14%
<br>
Attribute C: 15.5%
</td>
I managed to get the data in the following format as an array of arrays. I did this by splitting the long string with the following code:
row.xpath('tr').each_with_index do |td, j|
split_array << td.text.squish.split('%')
end
Here is the partial output of split_array:
[["Level: 1 Attribute A: 24", "Attribute B: 14", "Attribute C: 15.5"],["Level: 2 Atribute A: 36", ..etc]..etc]
I need to:
get rid of the Level: 1, Level: 2... from the first element in each array
split the Attribute Name and the float values into their own field
convert those parts into an array of hashes that looks similar to this:
[{:statistic => "Attribute A", :level_1 => 24.0, :level_2 =>36},{:statistic => "Attribute B", :level_1 => 14.0,:level_2 => 24},{:statistic => "Attribute C", :level_1 => 15.5, :level_2 => 34}]
I'm asking for code, pseudo code, or ideas that will send me in the right direction to convert my array of arrays into the array of hashes I outlined above.
1) Rather than gulp in a <td> string with different kinds of information and then parse them, I suggest storing them in meaningful variables to begin with. For example, store the level in 1 variable and the array of attribute statistics in another, getting them using the parsing facilities provided by Nokogiri.
2) Regarding these strings:
"Attribute B: 14"
Here is a script containing and illustrating a method that will parse them:
#!/usr/bin/env ruby
def parse_attr_string(s)
a = s.split
name = a[1].gsub(':', '')
value = a[2].gsub('%', '').to_f
[name, value]
end
s = "Attribute B: 14"
name, value = parse_attr_string(s)
puts "Name: #{name}, Value: #{value}" # Name: B, Value: 14.0
3) Regarding the reorganizing of the data, how about trying to figure it out and express it in pseudocode and then posting what you come up with if you have any problems with it?
I am trying to use foreach loop in smarty after assigning an associative array with unordered keys but it is not working. I need both the keys and the values. How do I do this.
The assigned array :
$arr[34] = 'Profile';
$arr[70] = 'Logo';
$arr[300] = 'Items';
$this->assign('arr', $arr);
Have a look at foreach.
Example, adjusted to your array:
<ul>
{foreach $arr as $keyvar=>$itemvar}
<li>Key {$keyvar} : {$itemvar} </li>
{/foreach}
</ul>
The Smarty manual has some more examples to help you further if needed.
Can a cell with comma separated information be turned into a list? I've got uneven amounts of data (companies) and would like to just have it display as a basic List when the flag is clicked on in the Fusion Map.
Say I have:
Location: Seminole County, FL
Companies: Acme Co, Box Inc, Cogs LLC
------
Location: Orange County, FL
Companies: Acme Co, Dirt Inc, Shell Co
On Map it should be two flags, which it is. But how can I then have the companies displayed as a basic list?
I can go into the record and change it to contain the HTML:
Companies:<ul><li>Acme Co</li><li>Box Inc</li><li>Shell Co</li></ul
but that's pretty clunky. Is there a way to template it into the Custom Info Window to automate this:
I looked online but couldn't find anything and the Fusion User Group says to ask here.
Edit:
Based on first answer, my rows:
Resulting problem:
If you format the Companies values as JSON lists, you can loop over them with Closure templates. The latter are described in this help page, though the looping constructs are not currently documented.
First, go to Edit > Change columns and set the format of the Companies to JSON text. Then format your values as, say, ["Acme Co", "Dirt Inc", "Shell Co"]. Then in the Closure template you can loop over it it with
{template .contents}
...wrapper div and other columns if desired...
Companies:
<ul>
{foreach $company in $data.value.Companies}
<li>{$company}
{/foreach}
</ul>
...other stuff...
{/template}
In my Ng-grid cell,i have applied this cell template. i'm getting data but with duplicated regionName.
<select ng-cell-input
ng-options="l.RegionID as l.RegionName for l in regionActivities"
ng-class="'colt' + $index" ng-model="COL_FIELD" ng-input='COL_FIELD' ng-change="activityRegionChange(row)" ng-show='!isRoomRequestInProgress'></select>
{{COL_FIELD}}
is there any way to prevent duplicates?
What you need to do is building or reusing a unique filter
<select ng-cell-input
ng-options="l.RegionID as l.RegionName for l in regionActivities | unique:'RegionName'"
ng-class="'colt' + $index" ng-model="COL_FIELD" ng-input='COL_FIELD' ng-change="activityRegionChange(row)" ng-show='!isRoomRequestInProgress'></select>
i have like a 2 foreach loops, first one with a image. So thats only the first item. But in me second foreach i wanted to start showing the result at array 1. Not 0 then i have like 2 times the second post.
First foreach
{foreach $cm->find('title,url,auteur,datum,reacties,topics,afbeelding,tekst', 'Blog') as $item}
{if $item#first}
{/if}
{/foreach}
Second for each
{foreach $cm->find('title,url,auteur,datum,reacties,topics,tekst', 'Blog') as $item}
{/foeach}
What do i need to add in me second foreach to start showing my results started by array 1.
Sorry if this a noob question, im not really good at smarty.
You can skip the first item in the second foreach with {continue}:
{foreach $cm->find('title,url,auteur,datum,reacties,topics,afbeelding,tekst', 'Blog') as $item}
{if $item#first}
{continue}
{/if}
... code for the other items here ...
{/foreach}