2

This might at first seem as a computer science question, but it is actually a mathematical question, since I am searching for a (particular?) function.

Let me phrase the problem I am trying to solve: Suppose, as the title suggests, that we have a menu with items that are getting clicked, and we are counting the clicks aiming to change the size of the items according to clicks, i.e. more clicks mean larger size. How are we to do that?

I have already found a nice way to compose a helpful data structure from the clicks made, which I am going to present now : We assign every item an arrow, $\cap$ is an up arrow and $\cup$ is a down arrow. Every item has a counter set to zero and an arrow set to $\cap$. With every click, regardless of item hit, every counter is increased or decreased by one, according to the arrows, ascending or descending. The particular item hit has the direction of its arrow changed after the counter is changed. The arrows are essentially mutable states. The data structure we are interested in is the record of each counter, i.e. a finite list of integers that go up and down by $1$

I want to use some function of these lists to determine the size of each item. Our program has essentially been given program time, with a "second" passing every time the user clicks on any item. I really like this data structure of records of counters, since it gives a lot more information than just the number of hits for each item. For example, an item that gets hit every "second", goes back and forth. An item that doesn't get hit a lot strays far away from the center of the system, which is zero. Having multiple items, i.e. multiple counter records gives room for intercorrelation between items, so that changing the size becomes dynamical and precise.

I cannot yet think of a good function, it could be that there is no best function. Probability and statistics might help, because we are essentially tinkering with the distribution of clicks.

So, with a slight abuse in terminology, I am looking for $F : \{records\} \rightarrow \{sizes\}$ where $F$ has to at least respect that $\{more$ $hits \Rightarrow larger$ $size\}$ for each record.

To make this rigorous, let $s$ be a finite list of integers. $s$ is called a record if-f $s(0)=0$ and $|s(n+1) - s(n)| = 1, \forall n \in \{1,2,...\}$. Let $R$ be the set of all records and $R^m$ be records of length $m$.

If two records, $r_1, r_2$ differ only by some non-empty tail of $r_2$, $t$ and $\exists n_0, r_2(n_0 - 2) \in t$ such that $r_2(n_0 - 1) > r_2(n_0 - 2), r_2(n_0)$, or the opposite inequality holds, we say that $r_1 < r_2$.

We are looking for a family of functions, $\mathcal{F}=\{F_m : R^m \rightarrow \mathcal{N}\}_{m \in \mathcal{N}}$, where $\mathcal{N}$ are the natural numbers representing sizes for records, such that;

$\forall r_1, r_2 \in \mathcal{R}$ with lengths $m_1, m_2$ respectively, we have that $r_1 < r_2 \Rightarrow F_{m_1}(r_1) < F_{m_2}(r_2)$

Some clarifications. $m$ plays the role of program time, so we need to differentiate between records of length $m$ and $m' \neq m$. The last condition asks that if a record could be the predecessor of some other record, and hits have increased, size should increase as well. This last part is up to interpretation actually, since one could argue that it is sort of a weak condition. Someone could interpret sizes as being rational numbers, or find some different way to express the non formal condition, as initially stated by the problem.

Remember as well, that the family $\mathcal{F}$ is to be applied on finite collections of records, of same length, as they share program time, i.e. elements $\in {(\mathcal{R}^m)}^N$ where $N$ is the number of items currently on the menu. I feel like there is a normed space hiding around this place, as there is a particular record that can be interpreted as zero, the forever ascending record without an infinite tail, which represents inactivity for an item.

NOTES : One could argue that size should decay given some period of inactivity.

An example run with four items on the menu, after three clicks, could look like this: Suppose I click items 1,4,3 in that order. Then our data would be four sequences of integers, as follows :

$s_1 = (0,1,0,-1)$

$s_2 = (0,1,2,3)$

$s_3 = (0,1,2,3)$, with the arrow looking down, so that in the next click it will descend,

$s_4 = (0,1,2,1)$.

EDIT : (I am continuously editing this question as I am working on my own on this problem as well)

Jason
  • 662
  • 2
    Why do you want to use this complicated data structure to save the click history? It contains exactly the same information as saving the list of clicks to the menu items including the order. – Tzimmo Sep 17 '24 at 10:20
  • Exactly. Including the order. It just seems interesting to work with. – Jason Sep 17 '24 at 16:51
  • Choose a sensible metric for the size of the entries first, then choose a data structure fit for computing it. Doing it the other way round is asking for inefficiency at best and nonsense at worst. In your case, you are basically saving the entire click history while using way more disk space. – Tzimmo Sep 17 '24 at 16:56
  • Yes but as I said, this is a mathematical question, I do not look at efficiency. – Jason Sep 18 '24 at 03:43
  • I do not mind giving clarifications, but I think it is already a long post. – Jason Sep 18 '24 at 03:44
  • As far as efficiency is concerned, we can get the same structure by saving just the change in direction and the total amount of hits, but mathematically it makes little difference. – Jason Sep 18 '24 at 03:46
  • As a bonus, I am writing in haskell, so translating math into code is easy, and I am only interested in the mathematical viewpoint. – Jason Sep 18 '24 at 03:49

2 Answers2

1

EDIT: THIS IS NOT A SOLUTION (I misunderstood what data is stored, so this answer does not address what is asked for)

I think your data structure does not carry much information about the number of hits to a given item. A function like the one you described seems infeasible.

Imagine having just two items. The record starts at $(0\cap, 0\cap)$. Now hit the first item a large even number of times. Let's say $1000$ times. The first entry flip-flops around while tve second one goes up every time. We arrive at $(0\cap,1000\cap)$. Now hit the second item: $(1\cap,1001\cup)$. And now the first one again, $1001$ times. What happens is the same as before, but now the second entry decreases. Result: $(2\cup, 0\cup)$. Now second item again, then first one: $(0\cap, 0\cap)$.

A function $F$ from records to sizes would therefore handle this situation ($2002$ clicks vs. $2$ clicks) exactly like the initial state (no clicks for either). Is that really what you want?

What makes the whole concept even more disturbing to me: Tiny differences can result in huge differences in the resulting record. If instead of one click to the second item after the initial $1000$, we had two, the second counter would have continued to grow. One more click for item number two changes its displacement from $0$ to something around $2000$. And didn't you say more clicks should mean less displacement?

Tzimmo
  • 3,166
  • I get what you are saying, but my data structure is the record of all changes of counters, i think you missed that. – Jason Sep 17 '24 at 10:14
  • 1
    Ah, that was not clear to me from the question. I thought the "record of each counter" refers to the counters for the different items. Maybe edit the question to make that clear. – Tzimmo Sep 17 '24 at 10:18
  • I will, thanks. – Jason Sep 17 '24 at 13:02
0

DISCLAIMER :
I am not sure what the Data Structures are supposed to contain , given that there is no Example in the Question.
It is not clear why each Item has some arrow $\cup,\cap$ (Comment : $\uparrow,\downarrow$ is more intuitive)
It is not clear why clicked Item will toggle up/down while the other items will stray away.
It is not clear why we have to compare at two times $m_1,m_2$ rather than compare two items.
It is not clear what the Sizes should be when two items have the same time , with variations in the clicking order.

My Solution :
Let the "Item Click" Data Structure be a list of Zeros&Ones $C_1=[0,0,1,0,0,0,1,0,0]$ , where $1$ indicates that it was clicked at time $m$ , while naturally , $0$ indicates no click.
We have the same DS for each Item , while we ensure that there is at most one $1$ in only one Item for each $m$

Here is the Example with 4 Clickable Items :
$C_1=[0,0,1,0,0,0,1,0,0]$
$C_2=[1,0,0,0,0,0,0,0,0]$
$C_3=[0,0,0,1,0,1,0,0,\color{red}1]$
$C_4=[0,0,0,0,0,0,0,0,\color{red}1]$

There were no clicks at $m=2,5,8$ , while there is something wrong at $m=9$ , where we incorrectly have two clicks , which the DS will have to handle to ensure that there is at most one $1$ in only one Item for each $m$

We also assign a Size to the DS , which will initially be $1$.
Every click will make it larger. The Increment could be always $1$ , it could be something else , according to "taste" , to make the change visible.

Hence DS will like like this :
$C_1=\{Size=3,Clicks=[0,0,1,0,0,0,1,0,0]\}$
$C_2=\{Size=2,Clicks=[1,0,0,0,0,0,0,0,0]\}$
$C_3=\{Size=4,Clicks=[0,0,0,1,0,1,0,0,\color{red}1]\}$ (Data rectified)
$C_4=\{Size=1,Clicks=[0,0,0,0,0,0,0,0,\color{red}0]\}$ (Data rectified)

It is now just a matter of appending a Zero or a One to each DS , while updating the Size. We show the Item with the Size , either taking the absolute magnitude or taking the relative magnitude (Size compared to Sum of Sizes of all)

Prem
  • 14,696
  • I have added an example. I have to note, you only try to address my question in your last paragraph. – Jason Sep 27 '24 at 18:42
  • The arrow is a mutable state, it doesn't matter in the end. You could though, save the sequence of arrows for each item and get the same data. – Jason Sep 27 '24 at 18:46
  • The condition in the end is rather arbitrary and created on the spot, just to give an example of how things could work. – Jason Sep 27 '24 at 18:49