Are there good example codes of implementations of factor graph sum-product scheduling? I am new to the concept, and would like to see how it gets implemented.
Dynamic integer will be any number from 0 to 150.
i.e. - number returns 41, need to return 50. If number is 10 need to return 10. Number is 1 need to return 10.
Was thinking I could use the ceiling function if I modify the integer as a decimal...? then use ceiling function, and put back to decimal?
Only thing is would also have to know if the number is 1, 2 or 3 digits (i.e. - 7 vs 94 vs 136)
Is there a better way to achieve this?
Thank You,
assume there are three group of high dimension vectors:
{a_1, a_2, ..., a_N},
{b_1, b_2, ... , b_N},
{c_1, c_2, ..., c_N}.
each of my vector can be represented as: x = a_i + b_j + c_k, where 1 <=i, j, k <= N. then the vector is encoded as (i, j, k) wich is then can be decoded as x = a_i + b_j + c_k.
my question is, if there are two vector: x = (i_1, j_1, k_1), y = (i_2, j_2, k_2), is there a method to compute the euclidian distance of these two vector without decode x and y.
There's a few questions discussing Merge sorting a LinkedList, but how can I do it with the C# LinkedList?
Since the LinkedListNode Next and Previous properties are read-only most of the in-place algorithms I've come across are not possible.
I've resorted to removing all the nodes, sorting them with a .OrderBy(node = node.Value) and then re-inserting them into the Linked list, but it's fairly crude.
My problem is very simple but I haven't found an efficient implementation yet.
Suppose there is a matrix A like this:
0 0 0 0 0 0 0
4 4 2 2 2 0 0
4 4 2 2 2 0 0
0 0 2 2 2 1 1
0 0 0 0 0 1 1
Now I want to find all starting positions of rectangular areas in this matrix which have a given size. An area is a subset of A where all numbers are the same.
Let's say width=2 and height=3. There are 3 areas which have this size:
2 2 2 2 0 0
2 2 2 2 0 0
2 2 2 2 0 0
The result of the function call would be a list of starting positions (x,y starting with 0) of those areas.
List((2,1),(3,1),(5,0))
The following is my current implementation. "Areas" are called "surfaces" here.
case class Dimension2D(width: Int, height: Int)
case class Position2D(x: Int, y: Int)
def findFlatSurfaces(matrix: Array[Array[Int]], surfaceSize: Dimension2D): List[Position2D] = {
val matrixWidth = matrix.length
val matrixHeight = matrix(0).length
var resultPositions: List[Position2D] = Nil
for (y <- 0 to matrixHeight - surfaceSize.height) {
var x = 0
while (x <= matrixWidth - surfaceSize.width) {
val topLeft = matrix(x)(y)
val topRight = matrix(x + surfaceSize.width - 1)(y)
val bottomLeft = matrix(x)(y + surfaceSize.height - 1)
val bottomRight = matrix(x + surfaceSize.width - 1)(y + surfaceSize.height - 1)
// investigate further if corners are equal
if (topLeft == bottomLeft && topLeft == topRight && topLeft == bottomRight) {
breakable {
for (sx <- x until x + surfaceSize.width;
sy <- y until y + surfaceSize.height) {
if (matrix(sx)(sy) != topLeft) {
x = if (x == sx) sx + 1 else sx
break
}
}
// found one!
resultPositions ::= Position2D(x, y)
x += 1
}
} else if (topRight != bottomRight) {
// can skip x a bit as there won't be a valid match in current row in this area
x += surfaceSize.width
} else {
x += 1
}
}
}
return resultPositions
}
I already tried to include some optimizations in it but I am sure that there are far better solutions. Is there a matlab function existing for it which I could port? I'm also wondering whether this problem has its own name as I didn't exactly know what to google for.
Thanks for thinking about it! I'm excited to see your proposals or solutions :)
Say you have 100000000 32-bit floating point values in an array, and each of these floats has a value between 0.0 and 1.0. If you tried to sum them all up like this
result = 0.0;
for (i = 0; i < 100000000; i++) {
result += array[i];
}
you'd run into problems as result gets much larger than 1.0.
So what are some of the ways to more accurately perform the summation?
I know what algorithms are, but I have never consciously used or created one for any of the programming that I have done. So I'd like to get a book about the subject - I'd prefer if it was in python but that's not a strict requirement. What book about algorithms helped you most to understand, use, and create algorithms?
One book per answer so they can be voted on...
We have a GWT application that needs to display various holidays. Is there a library available to do these calendrical calculations? If not, we'll have to do our own that we can ingest a set of rules to.
Cheers
For example, input is
Array 1 = [2, 3, 4, 5]
Array 2 = [3, 2, 5, 4]
Minimum number of swaps needed are 2.
The swaps need not be with adjacent cells, any two elements can be swapped.
I need to be able to determine if two sounds are very similar. The goal is to have a very limited vocabulary (10 or 15) of short one or two syllable words, then compare a captured sound to determine if it is one of those items with all the usual variability in environmental and capture conditions. The idea is that the user can issue a few simple commands by voice instead of keyboard or mouse.
Does anyone know the best approach to this? I don't want to do full blown speech recognition, just something much more limited.
Running my app through callgrind revealed that this line dwarfed everything else by a factor of about 10,000. I'm probably going to redesign around it, but it got me wondering; Is there a better way to do it?
Here's what I'm doing at the moment:
int i = 1;
while
(
(
(*(buffer++) == 0xffffffff && ++i) ||
(i = 1)
)
&&
i < desiredLength + 1
&&
buffer < bufferEnd
);
It's looking for the offset of the first chunk of desiredLength 0xffffffff values in a 32 bit unsigned int array.
It's significantly faster than any implementations I could come up with involving an inner loop. But it's still too damn slow.
hi, i have a mathematical problem which is a bit hard to describe, but i'll give it a try anyway.
in a timeline, i have a number of frames, of which i want to skip a certain number of frames, which should be evenly distributed along the timeline.
for example i have 10 frames and i want to skip 5, then the solution is easy: we skip every second frame.
10/5 = 2
if (frame%2 == 0)
skip();
but what if the above division does result in a floating number?
for example in 44 frames i want to skip 15 times. how can i determine the 15 frames which should be skipped?
thanks!
We have 40K+ groups in our active directory and we are increasingly facing problem of circular nested groups which are creating problems for some applications.
Does anyone know how to list down the full route through which a circular group membership exists ?
e.g.
G1 --> G2 --> G3 --> G4 --> G1
How do I list it down.
i have this thingy here :
function numOfPackets(bufferSize, packetSize) {
if (bufferSize <= 0 || packetSize > bufferSize) return 0;
if (packetSize < 0) throw Error();
var out = 0;
for(;;){
out++;
bufferSize = bufferSize - packetSize;
if( packetSize > bufferSize ) break;
}
return out;
}
which i run at often , can u give me more efficent variant of it?
I'm quite interested in automatic images translation
to 3d models. Not really for commercial product, but
from the point of possible academic research and implementation.
What I'd like to achieve is almost transparent for user process
of transformation series of images (fewer is better) to 3d
model which might be shown in flash/silverlight/javafx or similar.
Consider online furniture store with 3d models of all items
in stock. Kinda cool to have ability to see the product in 3d
before purchasing it.
I managed to find a few pieces of software, like insight3d,
but it couldn't be used in my case I guess.
So, are there any similar projects or tips for me?
If it would require to write that piece of software - I'd
really love to dig into research on this field.
Not a real question because I already found out the answer, but still interesting thing.
I always thought that hash table is the fastest associative container if you hash properly.
However, the following code is terribly slow. It executes only about 1 million iterations and takes more than 2 minutes of time on a Core 2 CPU.
The code does the following: it maintains the collection todo of items it needs to process. At each iteration it takes an item from this collection (doesn't matter which item), deletes it, processes it if it wasn't processed (possibly adding more items to process), and repeats this until there are no items to process.
The culprit seems to be the Dictionary.Keys.First() operation.
The question is why is it slow?
Stopwatch watch = new Stopwatch();
watch.Start();
HashSet<int> processed = new HashSet<int>();
Dictionary<int, int> todo = new Dictionary<int, int>();
todo.Add(1, 1);
int iterations = 0;
int limit = 500000;
while (todo.Count > 0)
{
iterations++;
var key = todo.Keys.First();
var value = todo[key];
todo.Remove(key);
if (!processed.Contains(key))
{
processed.Add(key);
// process item here
if (key < limit) { todo[key + 13] = value + 1; todo[key + 7] = value + 1; }
// doesn't matter much how
}
}
Console.WriteLine("Iterations: {0}; Time: {1}.", iterations, watch.Elapsed);
This results in:
Iterations: 923007; Time: 00:02:09.8414388.
Simply changing Dictionary to SortedDictionary yields:
Iterations: 499976; Time: 00:00:00.4451514.
300 times faster while having only 2 times less iterations.
The same happens in java.
Used HashMap instead of Dictionary and keySet().iterator().next() instead of Keys.First().
I have a data structure containing a list of objects, like this:
class A {
private List<Object> list;
}
How to properly define a hash function for the list, assuming each element of the list has correct hashCode()?
(It's strange that I couldn't easily find the solution via Google.)
One articles can be posted on many sites
the same article on a specific website can be visited by several different urls.
How do I reduce duplicated stuff in the above occasions?
I have a game that one player X wants to pass a ball to player Y, but he can be playing with more than one player and the others players can pass the ball to Y.
I want to know how many different paths can the ball take from X to Y?
for example if he is playing with 3 players there are 5 different paths, 4 players 16 paths, if he is playing with 20 players there are 330665665962404000 paths, and 40 players 55447192200369381342665835466328897344361743780 that the ball can take.
the number max. of players that he can play with is 500.
I was thinking in using Catalan Numbers? do you think is a correct approach to solve this?
Can you give me some tips.
I am wondering how I can find the number of intervals that intersect with the ones before it.
for the intervals [2, 4], [1, 6], [5, 6], [0, 4], the output should be 2. from [2,4] [5,6] and [5,6] [0,4].
So now we have 1 set of intervals with size n all containing a point a, then we add another set of intervals size n as well, and all of the intervals are to the right of a. Can you do this in O(nlgn) and O(nlg^2n)?
In C#, Say you have an array of strings, which contain only characters '0' and '1':
string[] input = { "0101", "101", "11", "010101011" };
And you'd like to build a function:
public void IdentifySubstrings(string[] input) { ... }
That will produce the following:
"0101 is a substring of 010101011"
"101 is a substring of 0101"
"101 is a substring of 010101011"
"11 is a substring of 010101011"
And you are NOT able to use built-in string functionality (such as String.Substring).
How would one efficiently solve this problem? Of course you could plow through it via brute force, but it just feels like there ought to be a way to accomplish it with a tree (since the only values are 0's and 1's, it feels like a binary tree ought to fit somehow). I've read a little bit about things like suffix trees, but I'm uncertain if that's the right path to be going down.
Any efficient solutions you can think of?
Given a 1*N matrix or an array, how do I find the first 4 elements which have the same value and then store the index for those elements?
PS:
I'm just curious. What if we want to find the first 4 elements whose value differences are within a certain range, say below 2? For example, M=[10,15,14.5,9,15.1,8.5,15.5,9.5], the elements I'm looking for will be 15,14.5,15.1,15.5 and the indices will be 2,3,5,7.
Hi,
I have this code for Node rotation and in a line which is marked something happens and I don't really know what and why :).
//Test case
30
\
16
/
29
RotationRight(node->mParent); //call
template<class T>
void SplayTree<T>::RotationRight(SplayNode<T> *&node) const
{
SplayNode<T> *left = node->mLeft;
SplayNode<T> *parent = node->mParent;
node->mLeft = left->mRight;
if(left->HasRight())
left->mRight->mParent = node;
left->mRight = node; //node in this line points to 0x00445198 {30}
left->mParent = node->mParent; //and in this line it points to 0x00444fb8 {16} (node, not node->mParent)
node->mParent = left;
node = left;
}
Well, left-mParent points to node also, so I basically do node = node-mParent. The problem is I can't find a work around - how to unpin in from node and change it's pointing address without changing it's.
I need to know a code that will automatically:-
search a specific word in excel
notes it row or column number (depends on data arrangement)
searches numerical type values in the respective row or column
with that numeric value(suppose a[7][0]or a[0][7]) it compares all other values of respective row or column(ie. a[i][0] or a[0][i])
sets that value to the highest value only if IT HAS GOT NO FORMULA FOR DERIVATION
i know most of coding but at a few places i got myself stuck...
i'm writing a part of my program upto which i know:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using Microsoft.Office.Interop;
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application oExcelApp;
namespace a{
class b{
static void main(){
try
{
oExcelApp = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application"); ;
if(oExcelApp.ActiveWorkbook != null)
{Excel.Workbook xlwkbook = (Excel.Workbook)oExcelApp.ActiveWorkbook;
Excel.Worksheet ws = (Excel.Worksheet)xlwkbook.ActiveSheet;
Excel.Range rn;
rn = ws.Cells.Find("maximum", Type.Missing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart,Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, false, Type.Missing, Type.Missing);
}}}
now ahead of this i only know tat i have to use cell.value2 ,cell.hasformula methods.....
& no more idea
can any one help me with this..
Given a sequence,say,
222
We have to put a '+' or '* ' between each adjacent pair.
'* ' has higher precedence over '+'
We have to o/p the string whose evaluation leads to minimum value.
O/p must be lexicographically smallest if there are more than one.
inp:222
o/p: 2*2+2
Explaination:
2+2+2=6
2+2*2=6
2*2+2=6
of this 3rd is lexicographically smallest.
I was wondering how to construct a DP solution for this.