Split QStringList in Chucks - qt5

Is there a function in QT to split a QStringList into sections/chunks?
For example, I have a QStringList with 100 items. I what to split it into 3. So for example I could get a
<QVector QStringList> sections;
with 3 sections: 1 section with 33 items, 2 section with 33 items, and 3 section with 34 items.
I can write a function for that but I was wondering if it's already there somewhere in QT

There is no such function in Qt. For further reference on what is possible with QStringList and what isn't check out the documentation

Related

Is there a way to generate random numbers between 0 and 500, but if first number is 300 not to deviate more than 20 for the next?

Is there a way to generate random numbers between 0 and 500, but if first number for example, is 300, not to deviate more than 20 for the next? I don't want 500 then 0 then 399 then 1. Thanks.
Just plug the first random number back into the "Random Number (Range)" built-in VI.
Bonus
Use a shift register to find a new random number within range of the last random number:
Previous answer refers to usage of minimal LabVIEW version 2019.
OpenG Numeric Library has similar function for generation of random number is the specified range, and supports earlier versions of LabVIEW.
Also, based on task description - if I've understood correctly - anyway random numbers should be in range 0 - 500; so we need to do additional check whether +/- 20 offset would not cause number "overflow".
Let me attach snippet of the solution which implements it. Note, that Select functions I've used just in order to show all the code on one snippet (instead of having Case Structure with pages).

Island Model in ECJ

In Genetic Programming (GP), when island model is used, does it mean that it will split the population size between islands?
For example, if in parameters file we have
pop.subpop.0.size = 4000
and we have 4 islands, does it mean that each island will have a population of size 1000? What if we put this line of code in parameters file of each island? Is it possible to have different population size for each island?
I'm using Java and ECJ package to implement island models in GP.
No, in your example you only have defined one island of 4000 individuals. The number is never automatically splited.
There are two ways to use Islands model in ECJ:
Using InterPopulationExchanger class:
One unique Java process that share variables. The islands are the subpopulations of the Population object. Therefore, you need to set sizes for each subpopulation in the parameter file. In your example, you only have set the island (subpopulation) 0 to 4000 individuals, but you should also set the other sizes. For example, for 10 islands of 4000 individuals each:
exch = ec.exchange.InterPopulationExchange
pop.subpops = 10
pop.subpop.0.size = 4000
pop.subpop.1.size = 4000
pop.subpop.2.size = 4000
...etc
pop.subpop.10.size = 4000
Using IslandExchanger class:
In this case, every island is executed in a different Java process, so, every islandID.params file (one per island/process) needs to set only one population:
exch = ec.exchange.InterPopulationExchange
pop.subpop.0.size = 4000
And the number of islands is set in the server.params file:
exch.num-islands = 10
You can see the rest of parameters and more information on page 223 of the ECJ documentation pdf: https://cs.gmu.edu/~eclab/projects/ecj/docs/manual/manual.pdf
I have not studied the ECJ package, but that is the general idea: you have a population which is divided in multiple subpopulations.
I don't know why you want subpopulations of different sizes. Is there a benefit compared to fixed-size subpopulations?
Anyway, I did a very simple implementation of a Genetic-Programming variant with multiple subpopulations. You can download it here: http://www.mepx.org/source_code.html
It is written in C++, but it should be very easy to understand by Java programmers.

Argument count limit of methods in Smalltalk-80 implementation

The maximum number of arguments of a method is limited to 2^5-1(i.e. 31) because there is only 5 bits to encode the number of arguments in a compiled method as illustrated in Figure 27.4 of the blue book. But the double extended send bytecode has 8 bits to encode the number of arguments (see the definition of doubleExtendedSendBytecode here), which means I can send as many as 2^8-1 (i.e. 127) arguments to a message (using perform: or the statement will not be compiled). Is this a contradiction? I think the bytecode uses too many bits to encode the number of arguments.
Yes, this is a contradiction but it did not yet matter enough.
Also, the number of arguments in a methods is bounded to the maximum number of temporary variables in a method, too, which in most Smalltalks happen to be 2^8-1.
There is another part to that:
In Squeak, the number of arguments is actually restricted to 15 (2^4-1), and also has only a nibble (4 bit) of space in the method header.
As the comment of Squeak's CompiledMethod states:
(index 18) 6 bits: number of temporary variables (#numTemps)
(index 24) 4 bits: number of arguments to the method (#numArgs)
with the #numTemps including the number of arguments, too.
Long story short, yes, the doubleExtendedSendBytecode could encode more arguments than actually expressible in a CompiledMethod.
This is one of the reasons it was replaced in Squeak by the doubleExtendedDoAnything bytecode that can do more than just sends, but limits the number of arguments to 2^5-1 (which is still more than the CompiledMethod can encode, but it is not unlikely that CompiledMethod will change in the foreseeable future to encode more than 15 arguments).
The actual number of arguments used is mostly small. The number of arguments of CompiledMethods in a Moose 4.6 Image I have here:
|bag|
bag := IdentityBag new.
CompiledMethod allInstances do:[ :element | bag add: element numArgs ].
bag sortedCounts
52006 -> 0
25202 -> 1
6309 -> 2
2133 -> 3
840 -> 4
391 -> 5
191 -> 6
104 -> 7
61 -> 8
12 -> 9
11 -> 10
5 -> 11
4 -> 12
3 -> 13
2 -> 15
1 -> 14

How does multiple assignment work?

From Section 4.1 of Programming in Lua.
In a multiple assignment, Lua first evaluates all values and only then
executes the assignments. Therefore, we can use a multiple assignment
to swap two values, as in
x, y = y, x -- swap x' fory'
How does the assignment work actually?
How multiple assignment gets implemented depends on what implementation of Lua you are using. The implementation is free to do things anyway it likes as long as it preserves the semantics. That is, no matter how things get implemented, you should get the same result as if you had saved all the values in the RHS before assigning them to the LHS, as the Lua book explains.
If you are still curious about the actual implementation, one thing you can do is see what is the bytecode that gets produced for a certain program. For example, taking the following program
local x,y = 10, 11
x,y = y,x
and passing it to the bytecode compiler (luac -l) for Lua 5.2 gives
main <lop.lua:0,0> (6 instructions at 0x9b36b50)
0+ params, 3 slots, 1 upvalue, 2 locals, 2 constants, 0 functions
1 [1] LOADK 0 -1 ; 10
2 [1] LOADK 1 -2 ; 11
3 [2] MOVE 2 1
4 [2] MOVE 1 0
5 [2] MOVE 0 2
6 [2] RETURN 0 1
The MOVE opcode assigns the value in the right register to the left register (see lopcodes.h in the Lua source for more details). Apparently, what is going on is that registers 0 and 1 are being used for x and y and slot 2 is being used as a temporary extra slot. x and y get initialized with constants in the first two opcodes and in the next three 3 opcodes a swap is performed using the "temporary" second slot, kind of like you would do by hand:
tmp = y -- MOVE 2 1
y = x -- MOVE 1 0
x = tmp -- MOVE 0 2
Given how Lua used a different approach when doing a swapping assignment and a static initialization, I wouldn't be surprised if you got different results for different kinds of multiple assignments (setting table fields is probably going to look very different, specially since then the order should matter due to metamethods...). We would need to find the part in the source where the bytecode gets emitted to be 100% sure though. And as I mentioned before, all of this might vary between Lua versions and implementations, specially if you look at LuaJIT vs PUC Lua.

senseval 2 dataset format

I wish to use Senseval-2 Coarse Sense Dataset but there is description available for the same (about the format of the dataset).
It is supposed to have the decision data i.e. whether two senses should be merged or not. Is the middle value a confidence measure? Also, they used a prerelease of Wordnet 1.7. Can I use Wordnet 1.7 for the same?
A sample from the file looks like :
material%5:00:00:physical:00 3 material%5:00:00:worldly:00
material%3:00:03:: 3 material%5:00:00:worldly:00
material%3:00:04:: 2 material%3:00:01::
material%3:00:02::
post%5:00:00:succeeding(a):00
present%3:00:01::
present%3:00:02::
present%3:01:00::
stone%3:01:00::
stone%5:00:00:chromatic:00
air%1:15:00:: 4 air%1:27:00::
air%1:19:00:: 4 air%1:27:00::
air%1:27:01:: 4 air%1:27:00::
air%1:04:00::
air%1:10:02::
air%1:07:00::
air%1:10:01::
appeal%1:04:00:: 3 appeal%1:10:00::
appeal%1:10:02:: 3 appeal%1:10:00::
Through inspection, the middle number actually describes how many senses are in the same merged sense. For example:
matrial%5:00:00:physical:00 3 material%5:00:00:worldly:00
material%3:00:03:: 3 material%5:00:00:worldly:00
basically says that there are 3 senses which is considered the same as material%5:00:00:worldly:00, which are the two senses provided in the two lines, and the sense itself.
You can see also that there are no number for senses that do not get merged, such as air%1:04:00, and for the sense material%3:00:04:: 2 material$2:00:01:: you can see that there are two senses. So you can do the merging by mapping the senses in the first position into the sense in the second position.