{'fraction_non_alphanumeric': 0.055903340191743645, 'fraction_numerical': 0.010200061287921901, 'mean_word_length': 3.77109440267335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
On Algorithmic Statistics for space-bounded algorithms

Algorithmic statistics studies explanations of observed data that are good in the algorithmic sense: an explanation should be simple i.e. should have small Kolmogorov complexity and capture all the algorithmically discoverable regularities in the data. However this idea can not be used in practice because Kolmogorov complexity is not computable. In this paper we develop algorithmic statistics using space-bounded Kolmogorov complexity. We prove an analogue of one of the main result of `classic' algorithmic statistics (about the connection between optimality and randomness deficiences). The main tool of our proof is the Nisan-Wigderson generator.


Introduction
In this section we give an introduction to algorithmic statistics and present our results.
We consider strings over the binary alphabet {0, 1}. We use |x| to denote the length of a string x. All of the logarithms are base 2. Denote the conditional Kolmogorov complexity 1 of x given y by C(x|y).

Introduction to Algorithmic Statistics
Let x be some observation data encoded as a binary string, we need to find a suitable explanation for it. An explanation (=model) is a finite set containing x. More specifically we want to find a simple model A such that x is a typical element in A. How to formalize that A is 'simple' and x is a 'typical element' in A? In classical algorithmic statistics a set A is called simple if it has small Kolmogorov complexity C(A) 2 . To measure typicality of x in A one can use the randomness deficiency of x as an element of A: d(x|A) := log |A| − C(x|A).
The randomness deficiency is always non-negative with O(log |x|) accuracy, as we can find x from A and the index of x in A. For most elements x in any set A the randomness deficiency of x in A is negligible. More specifically, the fraction of x in A with randomness deficiency greater than β is less than 2 −β .
There is another quantity measuring the quality of A as an explanation of x: the optimality deficiency: It is also non-negative with logarithmic accuracy (by the same reason). This value represents the following idea: a good explanation (a set) should not only be simple but also should be small.
One can ask: why as explanations we consider only sets-not general probability distributions? This is because for every string x and for every distribution P there exists a set A ∋ x explaining x that is not worse than P in the sense of deficiencies defined above 3 . Theorem 1 ( [15]). For every string x and for every distribution P there exists a set A ∋ x such that C(A|P ) ≤ O(log |x|) and 1 |A| ≥ 1 2 P (x). Kolmogorov called a string x stochastic if there exists a set A ∋ x such that C(A) ≈ 0 and d(x|A) ≈ 0. The last equality means that log |A| ≈ C(x|A) hence log |A| ≈ C(x) because C(A) ≈ 0. So, δ(x, A) is also small. 2 Kolmogorov complexity of A is defined as follows. We fix any computable bijection A → [A] from the family of finite sets to the set of binary strings, called encoding. Then we define C(A) as the complexity C([A]) of the code [A] of A. 3 The randomness deficiency of a string x with respect to a distribution P is defined as d(x|P ) := − log P (x) − C(x|P ), the optimality deficiency is defined as δ(x, P ) := C(P ) − log P (x) − C(x).
For example, an incompressible string of length n (i.e. a string whose complexity is close to n) is stochastic-the corresponding set is {0, 1} n . Non-stochastic objects also exist, however this fact is more complicatedsee [12,15].

Space-bounded Algorithmic Statistics
As mentioned by Kolmogorov in [4], the notion of Kolmogorov complexity C(x) has the following minor point. It ignores time and space needed to produce x from its short description. This minor point can be fixed by introducing space or time bounded Kolmogorov complexity (see, for example, [2] or [14]). In this paper we consider algorithms whose space (not time) is bounded by a polynomial of the length of a string.
The distinguishing complexity of a string x with space bound m is defined as the minimal length of a program p such that • p uses at most m bits of memory on every input. We denote this value by CD m (x). If for some x and m such a program p does not exist then CD m (x) := ∞. We say that p distinguishes x (from other strings) if p satisfies the first and the second requirements of the definition.
In this definition p(y) denotes V (p, y) for a universal Turing machine V . A Turing machine is called universal if for every machine U and for every q there exists p such that V (p, y) = U (q, y) for every y, |p| < |q| + O(1) and V uses space at most O(m) if U uses space m on input (q, y). Here the constant in O(m) depends on V and U but does not depend on q 4 . Now we extend this notion to arbitrary finite sets. The distinguishing complexity of a set A with space bound m is defined as the minimal length of a program p such that • p uses space m on every input.
Denote this value as CD m (A). The value CD a (x|A) is defined as the minimal length of a program that distinguishes x by using space at most m and uses A as an oracle. The value CD a (B |A) for an arbitrary finite set B is defined the same way.
How to define typicality of a string x in a set A? Consider the following resource-bounded versions of randomness and optimal deficiencies: One can show that these values are non-negative (with logarithmic accuracy) provided a ≥ p(|x|) and d ≥ p(|x| + b) for a large enough polynomial p.
We say that a set A is a good explanation for a string x (that belongs to A) if CD r (A) ≈ 0 (with O(log |x|) accuracy) and log |A| ≈ CD m (x). Here r and m are some small numbers. For such A the values d m (x|A) and δ r,m (x, A) are small.
It turns out that every string has a good explanation. Indeed, let x be a string such that CD m (x) = k. Define a set A ∋ x as {y | CD m (y) ≤ k}. The log-size of this set is equal to k up to a non-negative constant and hence log |A| = CD m (x). Note that A can be distinguished by a program of length O(log(k + m)) that uses poly(m) space.
So, for space-bounded algorithms all strings have good explanations (in other words, they are stochastic).

Distributions and Sets
Recall that in the classical algorithmic statistics for every distribution P and every x there is a finite set A ∋ x that is not worse than P as an explanation for x. It turns out that this the case also for space-bounded algorithmic statistics (otherwise we could not restrict ourselves to finite sets).
Before we formulate this result we give a definition of the complexity of a probability distribution P with space bound m that is denoted by C m (P ). This value is defined as the minimal length of a program p without input and with the following two properties. First, for every x the probability of the event [x output by p] is equal to P (x). Second, p uses space at most m (always). If such a program does not exist then C m (P ) := ∞. Theorem 2. There exist a polynomial r and a constant c such that for every string x, for every distribution P and for every m there exists a set A ∋ x such that CD r(m+n) (A) ≤ C m (P ) + c log(n + m) and 1 |A| ≥ P (x)2 −c log n . Here n is length of x.
The main tool of the proof of Theorem 2 is the theorem of Nisan "RL ⊆ SC", more precisely its generalization-Theorem 1.2 in [8].

Descriptions of Restricted Type
So far we considered arbitrary finite sets (or more general distributions) as models (statistical hypotheses). We have seen that for such class of hypotheses the theory becomes trivial. However, in practice we usually have some a priori information about the data. We know that the data was obtained by sampling with respect to an unknown probability distribution from a known family of distributions. For simplicity we will consider only uniform distributions i.e. a family of finite sets A.
For example, we can consider the family of all Hamming balls as A. (That means we know a priory that our string was obtain by flipping certain number of bits in an unknown string.) Or we may consider the family that consists of all 'cylinders': for every n and for every string u of length at most n we consider the set of all n-bit strings that have prefix u. It turns out that for the second family there exists a string that has no good explanations in this family: the concatenation of an incompressible string (i.e. a string whose Kolmogorov complexity is close to its length) and all zero string of the same length. (We omit the rigorous formulation and the proof.) Restricting the class of allowed hypotheses was initiated in [16]. It turns out that there exists a direct connection between randomness and optimality deficiencies in the case when a family is enumerable.

Theorem 3 ([16]). Let
A be an enumerable family of sets. Assume that every set from A consists of strings of the same length. Let x be a string of length n contained in A ∈ A. Then: In our paper we will consider families with the following properties: • Every set from A consists of strings of the same length. The family of all subsets of {0, 1} n that belong to A is denoted by A n .
• There exists a polynomial p such that |A n | ≤ 2 p(n) for every n.
• There exists an algorithm enumerating all sets from A n in space poly(n).
The last requirement means the following. There exists an indexing of A n and a Turing machine M that for a pair of integers (n; i) and a string x in the input outputs 1 if x belongs to i-th set of A n and 0 otherwise. On every such input M uses at most poly(n) space. Any family of finite sets of strings that satisfies these three conditions is called acceptable. For example, the family of all Hamming balls is acceptable. Our main result is the following analogue of Theorem 3.
Here p = p(m + n) and n is the length of x.
(b) For every acceptable family of sets A there exists a polynomial p such that the following property holds. For every A ∈ A, for every x ∈ A and for every integer m there exists a set B ∋ x from A such that Here s = p(m + n) and n is the length of x.
A skeptical reader would say that an analogue of Theorem 3 (b) should has the following form (and we completely agree with him/her).

Hypothesis 1.
There exist a polynomial p and a constant c such that for every set A ∋ x from A and for every m there exists a set B ∈ A such that Here p = p(m + n), n is the length of x and A is an acceptable family of sets.
We argue in Subsection 2.1 why Theorem 4 (b) is close to Hypothesis 1. Consider a program p of length CD m (x|A) that distinguishes x and uses A as an oracle. We need to construct a program that also distinguishes x but does not use any oracle. For this add to p a procedure distinguishing A. There exists such a procedure of length CD m (A). So, we get a program of the length that we want (additional O(log(CD m (A))) bits are used for pair coding) that uses poly(m) space.
So, for every x and A ∋ x the randomness deficiency is not greater than the optimal deficiency. The following example shows that the difference can be large.
Example 1. Consider an incompressible string x of length n, so C(x) = n (this equality as well as further ones holds with logarithmic precision). Let y be n-bit string that is also incompressible and independent of x, i.e. C(y|x) = n. By symmetry of information (see [13,5]) we get C(x|y) = n.
Define So, we can not just let A = B in Hypothesis 1. In some cases we have to 'improve' A (in the example above we can take {0, 1} n as an improved set).

Sketch of proof of Theorem 3(b)
The proof of Theorem 4 (b) is similar to the proof of Theorem 3 (b). Therefore we present the sketch of the proof of Theorem 3 (b).
Theorem 3 states that there exists a set B ∈ A containing x such that δ(x|B) ≤ d(x, A). (Here and later we omit terms of logarithmic order.) First we derive it from the following statement.
(1) There exists a set B ∈ A containing x such that |B| ≤ 2 · |A| and C(B) ≤ C(A) − C(A|x). For such B the δ(x|B) ≤ d(x, A) easily follows from the inequality C(A) − C(A|x) − C(x) ≤ − C(x|A). The latter inequality holds by symmetry of information.
To prove (1) note that (2) there exist at least 2 C(A|x) sets in A containing x whose complexity and size are at most C(A) and 2 · |A|, respectively.
Indeed, knowing x we can enumerate all sets from A containing x whose parameters (complexity and size) are not worse than the parameters of A.
Since we can describe A by its ordinal number in this enumeration we conclude that the length of this number is at least C(A|x) (with logarithmic precision). Now (1) follows from the following statement.
(3) Assume that A contains at least 2 k sets of complexity at most i and size at most 2 j containing x. Then one of them has complexity at most i−k.
(We will apply it to i = C(A), j = ⌈log |A|⌉ and k = C(A|x).) So, Theorem 4 (b) is an analogue of (2). Despite there is an analogue of symmetry of information for space-bounded algorithms (see [6] and Appendix) Hypothesis 1 does not follow Theorem 4 (b) directly. (There is some problem with quantifiers.) Proof of (3) is the main part of the proof of Theorem 3, the same thing holds for Theorem 4.
In the next subsection we derive Theorem 4 (b) from Lemma 2.2 (this is an analogue of the third statement). In the proof of Lemma 2.2 we use the Nisan-Wigderson generator.

Main lemma
We will derive Theorem 4 (b) from the following Lemma. For every acceptable family of sets A there exist a polynomial p and a constant c such that the following statement holds for every j.
Assume that a string x of length n belongs to 2 k sets from A n . Assume also that every of these sets has cardinality at most 2 j and space-bounded by m complexity at most i. Then one of this set is space-bounded by M complexity at most i − k + c log(n + m). Here M = m + p(n).

Theorem 4 ( b) from Lemma 2.2.
Denote by A ′ the family of all sets in A n containing x whose parameters are not worse than those of A.
We will describe A in k + O(log(n + m)) bits when x is known. The sets in A ′ (more specifically, their programs) can be enumerated if n, m and log |A| are known. This enumeration can be done in space poly(m + n). We can describe A by its ordinal number of this enumeration, so CD s (A|x) ≤ k + O(log(n + m)).
Theorem 4 (b) follows from Lemma 2.2 for i = CD m (A) and j = ⌊log |A|⌋.

Nisan-Wigderson generator. Proof of the main lemma
Define a probability distribution B as follows. Every set from A i,j n,m belongs to B with probability 2 −k (n + 2) ln 2 independently. We claim that B satisfies the following two properties with high probability.
(2) If a string of length n is contained in at least 2 k sets from A i,j n,m then one of these sets belongs to B. (1) and (2) with probability at least 1 2 . Proof. Show that B satisfies every of these two properties with probability at least 3 4 . For (1) it follows from Markov's inequality: the cardinality of B exceeds the expectation by a factor of 4 with probability less than 1 4 . (Of course we can get a rather more stronger estimation.)

Lemma. The family B satisfies the properties
To prove it for (2) consider a string of length n that belongs to at least 2 k sets from A i,j n,m . The probability of the event [every of these 2 k sets does not belong to B] is at most The probability of the sum of such events for all strings of length n is at most 2 n 2 −n−2 = 1 4 . Using Lemma 2.3 we can prove existence of a required set whose unbounded complexity is at most i − k + O(log(n + m)). Indeed, by Lemma 2.3 there exists a subfamily that satisfies the properties (1) and (2). The lexicographically first such family has small complexity-we need only know i, k, n and m to describe it. Note, that k and i are bounded by poly(n): since A is acceptable log |A n | = poly(n) and hence k is not greater than poly(n). We can enumerate all sets from A n , so space-bounded complexity of every element of A n (in particular, i) is bounded by polynomial in n. Now we can describe a required set as the ordinal number of an enumeration of this subfamily.
However, this method is not suitable for the polynomial space-bounded complexity: the brute-force search for the finding a suitable subfamily uses too much space (exponential). To reduce it we will use the Nisan-Wigderson generator. The same idea was used in [7]. • Function G m is computable in space poly(f ); • For every family of circuits C n of size q(v) and depth d and for large enough n it holds that: We will use this theorem for m = 2 i+n . Then f is a polynomial in i + n (if d is a constant), hence f = poly(n). Every element whose complexity is at most i corresponds to a string of length i in the natural way. So, we can assign subfamilies of A i,j n,m to strings of length m. Assume that there exists a circuit of size 2 O(n) and constant depth that inputs a subfamily of A i,j n and outputs 1 if this subfamily satisfies properties (1) and (2) from Lemma 2.3, and 0 otherwise. First we prove Lemma 2.2 using this assumption.
Compute G m (y) for all strings y of length f until we find a suitable one, i.e. whose image satisfies our two properties. Such a string exists by Lemma 2.3, Theorem 5 and our assumption. Note that we can find the lexicographically first suitable string by using space m + poly(n), so bounded by space m + poly(n) the complexity of this string is equal to O(log(n + m)).
So, if we can construct a constant depth circuit of the needed size that verifies properties (1) and (2) then we are happy. Unfortunately we do not know how to construct such a circuit verifying the first property (there exist problems with a computation of threshold functions by constant-depth circuits-see [3]). However, we know the following result. To use this theorem we make a little change of the first property. Divide A i,j n into 2 i−k parts of size 2 k . The corrected property is the following.
(1) * The family of sets B contains at most (n + k) 2 sets from each of these parts.
Lemma. The family of sets B satisfies properties (1) * and (2) with probability at least 1 3 . The proof of this lemma is not difficult but uses cumbersome formulas. We present the proof of Lemma 2.3 in Appendix.
of Lemma 2.2. It is clear that property (1) * implies property (1). Hence by using Lemma 2.2 and the discussion above, it is enough to show that properties (1) * and (2) can be verified by constant depth circuits of size 2 O(i+n) .
Such a circuit exists for property (1) * by Theorem 6. The second property can be verified by the following 2-depth circuit. For every string of length n containing in 2 k sets from A i,j n there exists a corresponding disjunct. All of these disjuncts go to a conjunction gate.

Proof of Theorem 2
Theorem 2 would have an easy proof if a program that corresponds to a distribution P could use only poly(n) random bits. Indeed, in such case we can run a program with all possible random bits and so calculate P (x) for every x in polynomial space. Hence, we can describe A as the set of all strings whose the probability of output is at least 2 −k , where 2 −k ≥ P (x) > 2 −k−1 .
In the general case (when the number of random bits is exponentially large) we will use the following theorem. Theorem 7 ([8]). Let f be a probabilistic program, that uses at most r(n) space on inputs of length n for some polynomial r. Assume that f always outputs 0 or 1 (in particular, f never loops). Then there exists a deterministic program f with the following properties: (a) f uses at most r 2 (n) space on inputs of length n; of Theorem 2. If the complexity of distribution P (bounded by space m) is equal to infinity then we can take {x} as A.
Else P can be specified by a program g. Consider the integer k such that: 2 −k+1 ≥ P (x) ≥ 2 −k . We can assume that k is not greater than n-the length of x-else we can take {0, 1} n as A.
Note, that we can find a good approximation for P (y) running g exponentially times.
More accurately, let us run g for 2 100k 2 times. For every string y denote by ω(y) the frequency of output of y. The following inequality holds by Hoeffding's inequality Hence by using program g we can construct a program f that uses poly(n) space (on inputs of length n) such that (1) if P (y) > 2 −k−1 and |y| = n then Pr[f (y) = 1] > 2 3 ; (2) if P (y) < 2 −k−2 then Pr[f (y) = 0] > 2 3 . Now using Theorem 7 for f we get a program f such that | f | ≤ |g| + O(log n). By the first property of f we get f (x) = 1. From the second property it follows that the cardinality of the set {y | f (y) = 1} is not greater than 2 k+2 . So, this set satisfies the requirements of the theorem.  k+1 . Denote by D A the pairs of D whose the first element is equal to A. Let t satisfy the inequalities 2 t ≤ |D A | < 2 t+1 .
Let us prove that • CD p (B |A) does not exceed t significantly; • CD p (A) does not exceed k − t significantly.
We start with the first statement. There exists a program that enumerates all sets from D A using A as an oracle and that works in space 2m+O(n). Indeed, such enumeration can be done in the following way: enumerate all programs of length k and verify the following condition for every pair of n-bit strings. First, a program uses at most m space on this input. Second, if a second n-bit string belongs to A then the program outputs 1, and 0 otherwise. Since some program loops we need aditional m + O(n) space to take it into account.
Append to this program the ordinal number of a program that distinguishes (A, B). This number is not greater than t + 1. Therefore we have CD p (B |A) ≤ t + O(log(CD m (A, B) + m + n)). Now let us prove the second statement. Note that there exist at most 2 k−t+1 sets U such that |D U | ≥ 2 t (including A). Hence, if we construct a program that enumerates all sets with such property (and does not use much space) then we will win-the set A can be described by the ordinal number of this enumeration.
Let us construct such a program. It works as follows: enumerate all sets U that are the first elements from D, i.e. we enumerate programs that distinguish the corresponding sets (say, lexicographically). We go to the next step if the following properties holds. First, |D U | ≥ 2 t , and second: we did not meet set U earlier (i.e. every program whose the lexicographical number is smaller does not distinguish U or is not the first element from a set from D).
This program works in 2m + poly(n + CD m (A, B)) space (that we want) and has length O(log(CD m (A) + n + m)).
of Lemma 2.3. Let us show that B satisfies property (1) * with probability at most 2 −n . Since B satisfies property (2) with probability at most 1 4 (see the proof of Lemma 2.3) it would be enough for us.
For this let us show that every part is 'bad' (i.e. has at least (n + k) 2 + 1 sets from B) with probability at most 2 −2n . The probability of such event is equal to the probability of the following event: a binomial random