RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-626172

polymamylop's questions

Martin Hope
polymamylop
Asked: 2024-12-16 07:11:00 +0000 UTC

创建马尔可夫链

  • 4

我写了代码,三步后的概率分布是1 0 0 0 0 0。我无法修复它。锻炼:

  1. 指定马尔可夫链:状态集、初始分布(所有情况)、转移概率矩阵、马尔可夫链图。
  2. 求马尔可夫链在任意一步的状态分布:输入,设置状态数,初始分布,步数。
  3. 对马尔可夫链的状态进行分类。变化:瓮中有 N 个白球。第一步,根据随机等概率选择方案从瓮中取出一个球并替换为黑色。状态集 - 白球的数量 我的代码:
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt

def create_transition_matrix(N):
    """
    Создает матрицу переходных вероятностей для задачи.
    """
    P = np.zeros((N+1, N+1))  # Матрица переходов размером (N+1) x (N+1)

    for k in range(N+1):
        if k > 0:  # Переход в состояние k-1 (вынут белый шар)
            P[k, k-1] = k / (k + (N-k))  # k белых из общего количества
        if k < N:  # Переход в то же состояние (вынут черный шар)
            P[k, k] = (N-k) / (k + (N-k))  # (N-k) черных из общего количества

    return P


def compute_distribution(P, pi0, steps):
    """
    Вычисляет распределение вероятностей на любом шаге.
    P: матрица переходных вероятностей.
    pi0: начальное распределение (вектор длины N+1).
    steps: число шагов.
    """
    pi_t = np.array(pi0)
    for _ in range(steps):
        pi_t = pi_t @ P  # Итеративное умножение для расчета распределения
    return pi_t

def classify_states(P):
    """
    Классифицирует состояния цепи Маркова.
    P: матрица переходных вероятностей.
    """
    N = P.shape[0]
    classifications = []
    for state in range(N):
        if np.all(P[:, state] == 0):  # Проверяем, поглощающее ли состояние
            classifications.append((state, "Поглощающее"))
        else:
            classifications.append((state, "Переходное"))
    return classifications

def draw_graph(P):
    """
    Строит граф цепи Маркова.
    P: матрица переходных вероятностей.
    """
    G = nx.DiGraph()
    N = P.shape[0]

    for i in range(N):
        for j in range(N):
            if P[i, j] > 0:
                G.add_edge(i, j, weight=round(P[i, j], 2))

    pos = nx.spring_layout(G)
    nx.draw(G, pos, with_labels=True, node_size=700, node_color="lightblue", font_size=10, font_weight="bold")
    edge_labels = nx.get_edge_attributes(G, 'weight')
    nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)
    plt.title("Граф цепи Маркова")
    plt.show()

# Параметры задачи
N = 5  # Число белых шаров в начале
P = create_transition_matrix(N)  # Матрица переходов

# 1. Матрица переходов и граф цепи Маркова
print("Матрица переходов P:")
print(P)

# Построим граф
draw_graph(P)

# 2. Распределение состояний
pi0 = [1] + [0] * N  # Начальное распределение: 100% белых шаров
steps = 3  # Число шагов
pi_t = compute_distribution(P, pi0, steps)

print(f"\nРаспределение вероятностей через {steps} шага(ов):")
print(pi_t)

# 3. Классификация состояний
classifications = classify_states(P)
print("\nКлассификация состояний:")
for state, class_type in classifications:
    print(f"Состояние {state}: {class_type}")

python
  • 1 个回答
  • 72 Views
Martin Hope
polymamylop
Asked: 2024-12-06 09:17:20 +0000 UTC

创建 Docker 容器时遇到的问题

  • 5

我安装了 OpenAi Universe

cd ~ git clone https://github.com/openai/universe.git
cd universe
pip install -e .

安装过程中出现这样的消息:

Obtaining file:///Users/user/universe
  Preparing metadata (setup.py) ... done
Requirement already satisfied: universe in /Users/user/universe (0.21.5)
Requirement already satisfied: autobahn>=0.16.0 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from universe==0.21.5) (24.4.2)
Requirement already satisfied: docker-py==1.10.3 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from universe==0.21.5) (1.10.3)
Requirement already satisfied: docker-pycreds==0.2.1 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from universe==0.21.5) (0.2.1)
Requirement already satisfied: fastzbarlight>=0.0.13 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from universe==0.21.5) (0.0.14)
Requirement already satisfied: go-vncdriver>=0.4.8 in /Users/danilabrikanov/go-vncdriver (from universe==0.21.5) (0.4.19)
Requirement already satisfied: gym>=0.8.1 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from universe==0.21.5) (0.26.2)
Requirement already satisfied: Pillow>=3.3.0 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from universe==0.21.5) (10.4.0)
Requirement already satisfied: PyYAML>=3.12 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from universe==0.21.5) (6.0.1)
Requirement already satisfied: six>=1.10.0 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from universe==0.21.5) (1.16.0)
Requirement already satisfied: twisted>=16.5.0 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from universe==0.21.5) (23.10.0)
Requirement already satisfied: ujson>=1.35 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from universe==0.21.5) (5.10.0)
Requirement already satisfied: requests<2.11,>=2.5.2 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from docker-py==1.10.3->universe==0.21.5) (2.10.0)
Requirement already satisfied: websocket-client>=0.32.0 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from docker-py==1.10.3->universe==0.21.5) (1.8.0)
Requirement already satisfied: txaio>=21.2.1 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from autobahn>=0.16.0->universe==0.21.5) (23.1.1)
Requirement already satisfied: cryptography>=3.4.6 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from autobahn>=0.16.0->universe==0.21.5) (43.0.0)
Requirement already satisfied: hyperlink>=21.0.0 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from autobahn>=0.16.0->universe==0.21.5) (21.0.0)
Requirement already satisfied: setuptools in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from autobahn>=0.16.0->universe==0.21.5) (75.1.0)
Requirement already satisfied: numpy in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from go-vncdriver>=0.4.8->universe==0.21.5) (1.26.4)
Requirement already satisfied: cloudpickle>=1.2.0 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from gym>=0.8.1->universe==0.21.5) (3.0.0)
Requirement already satisfied: gym_notices>=0.0.4 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from gym>=0.8.1->universe==0.21.5) (0.0.8)
Requirement already satisfied: attrs>=21.3.0 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from twisted>=16.5.0->universe==0.21.5) (23.1.0)
Requirement already satisfied: automat>=0.8.0 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from twisted>=16.5.0->universe==0.21.5) (20.2.0)
Requirement already satisfied: constantly>=15.1 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from twisted>=16.5.0->universe==0.21.5) (23.10.4)
Requirement already satisfied: incremental>=22.10.0 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from twisted>=16.5.0->universe==0.21.5) (22.10.0)
Requirement already satisfied: typing-extensions>=4.2.0 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from twisted>=16.5.0->universe==0.21.5) (4.11.0)
Requirement already satisfied: zope-interface>=5 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from twisted>=16.5.0->universe==0.21.5) (5.4.0)
Requirement already satisfied: cffi>=1.12 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from cryptography>=3.4.6->autobahn>=0.16.0->universe==0.21.5) (1.17.1)
Requirement already satisfied: idna>=2.5 in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from hyperlink>=21.0.0->autobahn>=0.16.0->universe==0.21.5) (3.7)
Requirement already satisfied: pycparser in /opt/anaconda3/envs/universe2/lib/python3.10/site-packages (from cffi>=1.12->cryptography>=3.4.6->autobahn>=0.16.0->universe==0.21.5) (2.21)
Installing collected packages: universe
  Attempting uninstall: universe
    Found existing installation: universe 0.21.5
    Uninstalling universe-0.21.5:
      Successfully uninstalled universe-0.21.5
  DEPRECATION: Legacy editable install of universe==0.21.5 from file:///Users/user/universe (setup.py develop) is deprecated. pip 25.0 will enforce this behaviour change. A possible replacement is to add a pyproject.toml or enable --use-pep517, and use setuptools >= 64. If the resulting installation is not behaving as expected, try using --config-settings editable_mode=compat. Please consult the setuptools documentation for more information. Discussion can be found at https://github.com/pypa/pip/issues/11457
  Running setup.py develop for universe
Successfully installed universe

接下来我需要创建一个 Docker 镜像:

docker build -t universe .

运行该命令后,创建时出现错误:

[+] Building 3.2s (10/18)                                  docker:desktop-linux
 => [internal] load build definition from Dockerfile                       0.0s
 => => transferring dockerfile: 1.48kB                                     0.0s
 => [internal] load metadata for docker.io/library/ubuntu:16.04            3.0s
 => [auth] library/ubuntu:pull token for registry-1.docker.io              0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 66B                                           0.0s
 => [ 1/13] FROM docker.io/library/ubuntu:16.04@sha256:1f1a2d56de1d604801  0.0s
 => [internal] load build context                                          0.0s
 => => transferring context: 13.44kB                                       0.0s
 => CACHED [ 2/13] RUN apt-get update     && apt-get install -y libav-too  0.0s
 => CACHED [ 3/13] RUN true                                                0.0s
 => CACHED [ 4/13] RUN ln -sf /usr/bin/pip3 /usr/local/bin/pip     && ln   0.0s
 => ERROR [ 5/13] RUN pip install gym[all]                                 0.2s
------                                                                          
 > [ 5/13] RUN pip install gym[all]:                                            
0.164 Traceback (most recent call last):                                        
0.164   File "/usr/local/bin/pip", line 7, in <module>                          
0.164     from pip._internal.cli.main import main                               
0.164   File "/usr/local/lib/python3.5/dist-packages/pip/_internal/cli/main.py", line 67
0.164     sys.stderr.write(f"ERROR: {exc}")
0.164                                    ^
0.164 SyntaxError: invalid syntax
------
Dockerfile:36
--------------------
  34 |     
  35 |     # Install gym
  36 | >>> RUN pip install gym[all]
  37 |     
  38 |     # Get the faster VNC driver
--------------------
ERROR: failed to solve: process "/bin/sh -c pip install gym[all]" did not complete successfully: exit code: 1

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/lzvq2rrk75dfl8bh6pc8k4wsr

我能做些什么来解决这个问题,我读了 Sudharsan Ravichandiran 的书《Python 中的深度强化学习》。因为这个问题我无法继续阅读。

Dockerfile:

FROM ubuntu:16.04

RUN apt-get update \
    && apt-get install -y libav-tools \
    python3-numpy \
    python3-scipy \
    python3-setuptools \
    python3-pip \
    libpq-dev \
    libjpeg-dev \
    curl \
    cmake \
    swig \
    python3-opengl \
    libboost-all-dev \
    libsdl2-dev \
    wget \
    unzip \
    git \
    golang \
    net-tools \
    iptables \
    libvncserver-dev \
    software-properties-common \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

ARG BASE_COMMAND="true"
RUN $BASE_COMMAND

RUN ln -sf /usr/bin/pip3 /usr/local/bin/pip \
    && ln -sf /usr/bin/python3 /usr/local/bin/python \
    && pip install -U pip

# Install gym
RUN pip install gym[all]

# Get the faster VNC driver
RUN pip install go-vncdriver>=0.4.0

# Install pytest (for running test cases)
RUN pip install pytest

# Force the container to use the go vnc driver
ENV UNIVERSE_VNCDRIVER='go'

WORKDIR /usr/local/universe/

# Cachebusting
COPY ./setup.py ./
COPY ./tox.ini ./

RUN pip install -e .

# Upload our actual code
COPY . ./

# Just in case any python cache files were carried over from the source directory, remove them
RUN py3clean .
python
  • 1 个回答
  • 30 Views
Martin Hope
polymamylop
Asked: 2024-09-23 21:45:38 +0000 UTC

在 C++ 中使用俄语字符

  • 4

帮我解决这个问题,我对C++了解不多,我们给出了以下任务:“给定一个字符串,你需要找到这一行中最长的单词,将其扩展,并在其他所有单词中更改大小写”您可以输入带有数字的俄语和英语符号。 ,不能使用字符串,只能使用字符数组。对我来说困难是我没有太多使用符号表,请帮助。

我尝试使用标准库,但对俄语字符不起作用。我也尝试过改变,但没有任何效果

c++
  • 1 个回答
  • 53 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5